Skip to content

Commit

Permalink
Get primary key from schema instance rather
Browse files Browse the repository at this point in the history
than schema class
  • Loading branch information
rbw committed Sep 22, 2020
1 parent 5e05818 commit f76648e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aiosnow/models/common/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ class BaseModel(metaclass=BaseModelMeta):

def __init__(self, client: Client):
self._client = client
self._primary_key = getattr(self.schema_cls, "_primary_key")
self.fields = dict(self.schema_cls.fields)
self.nested_fields = {
n: f for n, f in self.fields.items() if isinstance(f, Nested)
}
self.schema = self.schema_cls(unknown=marshmallow.EXCLUDE)
self._primary_key = getattr(self.schema, "_primary_key")

@property
@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions aiosnow/models/table/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ async def get_object_id(self, value: Union[Condition, str]) -> str:
"""

if isinstance(value, Condition):
record = await self.get_one(value, return_only=[self._primary_key])
return record.__dict__[self._primary_key]
response = await self.get_one(value, return_only=[self._primary_key])
return response.data[self._primary_key]
elif isinstance(value, str):
return value
else:
Expand Down

0 comments on commit f76648e

Please sign in to comment.