New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept Meta class inside entity models to override datastore.Client instance params #4
Conversation
@staticmethod | ||
def _to_camel_case(key: str) -> str: | ||
splited_key = key.split('_') | ||
return splited_key[0] + ''.join( | ||
[x.title() for x in splited_key[1:]] | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need it anymore
def _mount_google_entity(self, entity_dict: Dict) -> GoogleEntity: | ||
entity_key = entity_dict.pop("id") | ||
entity = GoogleEntity(entity_key) | ||
for key, value in entity_dict.items(): | ||
key_name = self._convert_property_name(key) | ||
entity[key_name] = value | ||
|
||
return entity | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
noseiquela_orm/client.py
Outdated
def _mount_google_entity(self, entity_dict: Dict, key_case: Callable) -> GoogleEntity: | ||
entity_key = entity_dict.pop("id") | ||
entity = GoogleEntity(entity_key) | ||
for key, value in entity_dict.items(): | ||
key_name = key_case(key) | ||
entity[key_name] = value | ||
|
||
return entity | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it here (from "Entity
") because I thought the context made more sense.
project=project, | ||
namespace=namespace, | ||
credentials=credentials, | ||
client_info=(client_info or _CLIENT_INFO), | ||
client_options=client_options, | ||
_http=_http, | ||
_use_grpc=_use_grpc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the default client settings (from google lib)
self._process_meta(attrs) | ||
self._define_datastore_client() | ||
self._define_case_style(attrs) | ||
self._mount_query() | ||
|
||
self._partial_key = KeyField( | ||
entity_kind=self.kind, | ||
project=self._project, | ||
namespace=self._namespace | ||
project=self.project, | ||
namespace=self.namespace | ||
) | ||
|
||
self._handle_properties_validation(attrs) | ||
self._handle_required_properties(attrs) | ||
self._handle_properties_default_value(attrs) | ||
self._handle_parent_key(attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've broken the steps/processes into functions, to make it easier to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
so it overwrites only for that model