
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
Access to orm_mode object in root validator Β· Issue #821 Β· pydantic/pydantic
Description:
Feature Request It would be nice if you could access the "source" object in a root_validator (coming soon; see #817) when the model was being initialized via a call to from_orm. This would enable almost any form of custom loading from an...
Website Age:
17 years and 9 months (reg. 2007-10-09).
Matching Content Categories {π}
- Personal Finance
- Games
- Real Estate
Content Management System {π}
What CMS is github.com built with?
Github.com employs WORDPRESS.
Traffic Estimate {π}
What is the average monthly size of github.com audience?
ππ Tremendous Traffic: 10M - 20M visitors per month
Based on our best estimate, this website will receive around 10,666,346 visitors per month in the current month.
check SE Ranking
check Ahrefs
check Similarweb
check Ubersuggest
check Semrush
How Does Github.com Make Money? {πΈ}
Subscription Packages {π³}
We've located a dedicated page on github.com that might include details about subscription plans or recurring payments. We identified it based on the word pricing in one of its internal links. Below, you'll find additional estimates for its monthly recurring revenues.How Much Does Github.com Make? {π°}
Subscription Packages {π³}
Prices on github.com are in US Dollars ($).
They range from $4.00/month to $21.00/month.
We estimate that the site has approximately 5,347,483 paying customers.
The estimated monthly recurring revenue (MRR) is $22,459,429.
The estimated annual recurring revenues (ARR) are $269,513,148.
Wordpress Themes and Plugins {π¨}
What WordPress theme does this site use?
It is strange but we were not able to detect any theme on the page.
What WordPress plugins does this website use?
It is strange but we were not able to detect any plugins on the page.
Keywords {π}
def, dmontagu, return, root, getterdict, class, selfoverrides, sign, object, issue, feature, obj, added, samuelcolvin, pydantic, access, ormmode, validator, request, fromorm, make, newly, item, default, mentioned, commented, prettywood, navigation, source, pull, requests, actions, security, closed, rootvalidator, model, making, overrides, initself, selfobj, slightly, check, performance, getattrselfobj, import, str, values, validators, github, type,
Topics {βοΈ}
personal information access pydantic import basemodel comment metadata assignees samuelcolvin mentioned root validator source type projects getterdict class class getterdict performance sacrifice feature def __init__ def keys def get_y issue access class mymodel pre=true orm_mode object custom loading pydantic supports setting projects milestone milestone relationships orm object make sense optional[dict] = return getattr return set source_object github make object' _obj = obj completed sign __setitem__ str = schema values mymodelorm def getterdict '_obj' return _obj basemodel object from_orm 'from_orm' make getattr schema
Payment Methods {π}
- Braintree
Questions {β}
- @samuelcolvin I can't think of any breaking changes this would introduce, can you?
- Already have an account?
Schema {πΊοΈ}
DiscussionForumPosting:
context:https://schema.org
headline:Access to orm_mode object in root validator
articleBody:# Feature Request
It would be nice if you could access the "source" object in a `root_validator` (coming soon; see #817) when the model was being initialized via a call to `from_orm`. This would enable almost any form of custom loading from an orm object possible by use of a root validator.
I think this can be accomplished now by making changes *only* to the `GetterDict` class:
```python
class GetterDict:
"""
Hack to make object's smell just enough like dicts for validate_model.
"""
__slots__ = ('_obj', '_overrides')
def __init__(self, obj: Any):
self._obj = obj
self._overrides: Optional[Dict] = None # NEWLY ADDED
# NEWLY ADDED
def source_object(self):
return self._obj
# NEWLY ADDED
def __setitem__(self, key, value):
if self._overrides is None:
self._overrides = {}
self._overrides.__setitem__(key, value)
def get(self, item: Any, default: Any) -> Any:
# SLIGHTLY MODIFIED
if self._overrides is None:
# This check could be removed if we make the _overrides non-optional
# but I think that would come with a *slightly* larger performance penalty if not used
return getattr(self._obj, item, default)
return self._overrides.get(item) or getattr(self._obj, item, default)
def keys(self) -> Set[Any]:
"""
We don't want to get any other attributes of obj if the model didn't explicitly ask for them
"""
return set()
```
The only performance sacrifice if not making use of the feature is the check if `self._overrides is None` (it seems to me like the impact would be miniscule in practice).
This would allow things like:
```python
from pydantic import BaseModel, Schema, root_validator
from pydantic.utils import GetterDict
class MyModelORM:
def __init__(self, x):
self.x = x
@property
def orm_property(self) -> str:
return "hello"
class MyModel(BaseModel):
x: int
y: str = Schema(None)
@root_validator(pre=True)
def get_y(cls, values):
if isinstance(values, GetterDict):
# This is how you know it got called via from_orm
values['y'] = values.source_object().orm_property
return values
class Config:
orm_mode = True
print(MyModel.from_orm(MyModelORM(x=1)))
# MyModel x=1 y='hello'
```
@samuelcolvin I can't think of any breaking changes this would introduce, can you? Would this be interesting to you?
author:
url:https://github.com/dmontagu
type:Person
name:dmontagu
datePublished:2019-09-18T19:06:35.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:3
url:https://github.com/821/pydantic/issues/821
context:https://schema.org
headline:Access to orm_mode object in root validator
articleBody:# Feature Request
It would be nice if you could access the "source" object in a `root_validator` (coming soon; see #817) when the model was being initialized via a call to `from_orm`. This would enable almost any form of custom loading from an orm object possible by use of a root validator.
I think this can be accomplished now by making changes *only* to the `GetterDict` class:
```python
class GetterDict:
"""
Hack to make object's smell just enough like dicts for validate_model.
"""
__slots__ = ('_obj', '_overrides')
def __init__(self, obj: Any):
self._obj = obj
self._overrides: Optional[Dict] = None # NEWLY ADDED
# NEWLY ADDED
def source_object(self):
return self._obj
# NEWLY ADDED
def __setitem__(self, key, value):
if self._overrides is None:
self._overrides = {}
self._overrides.__setitem__(key, value)
def get(self, item: Any, default: Any) -> Any:
# SLIGHTLY MODIFIED
if self._overrides is None:
# This check could be removed if we make the _overrides non-optional
# but I think that would come with a *slightly* larger performance penalty if not used
return getattr(self._obj, item, default)
return self._overrides.get(item) or getattr(self._obj, item, default)
def keys(self) -> Set[Any]:
"""
We don't want to get any other attributes of obj if the model didn't explicitly ask for them
"""
return set()
```
The only performance sacrifice if not making use of the feature is the check if `self._overrides is None` (it seems to me like the impact would be miniscule in practice).
This would allow things like:
```python
from pydantic import BaseModel, Schema, root_validator
from pydantic.utils import GetterDict
class MyModelORM:
def __init__(self, x):
self.x = x
@property
def orm_property(self) -> str:
return "hello"
class MyModel(BaseModel):
x: int
y: str = Schema(None)
@root_validator(pre=True)
def get_y(cls, values):
if isinstance(values, GetterDict):
# This is how you know it got called via from_orm
values['y'] = values.source_object().orm_property
return values
class Config:
orm_mode = True
print(MyModel.from_orm(MyModelORM(x=1)))
# MyModel x=1 y='hello'
```
@samuelcolvin I can't think of any breaking changes this would introduce, can you? Would this be interesting to you?
author:
url:https://github.com/dmontagu
type:Person
name:dmontagu
datePublished:2019-09-18T19:06:35.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:3
url:https://github.com/821/pydantic/issues/821
Person:
url:https://github.com/dmontagu
name:dmontagu
url:https://github.com/dmontagu
name:dmontagu
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:3
interactionType:https://schema.org/CommentAction
userInteractionCount:3
External Links {π}(2)
Analytics and Tracking {π}
- Site Verification - Google
Libraries {π}
- Clipboard.js
- D3.js
- GSAP
- Lodash
Emails and Hosting {βοΈ}
Mail Servers:
- aspmx.l.google.com
- alt1.aspmx.l.google.com
- alt2.aspmx.l.google.com
- alt3.aspmx.l.google.com
- alt4.aspmx.l.google.com
Name Servers:
- dns1.p08.nsone.net
- dns2.p08.nsone.net
- dns3.p08.nsone.net
- dns4.p08.nsone.net
- ns-1283.awsdns-32.org
- ns-1707.awsdns-21.co.uk
- ns-421.awsdns-52.com
- ns-520.awsdns-01.net