Skip to content

Commit

Permalink
Move auto_fields out of meta_
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Sep 1, 2021
1 parent a5d39a0 commit aa67f94
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/protean/adapters/repository/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from protean.port.dao import BaseDAO, BaseLookup, ResultSet
from protean.port.provider import BaseProvider
from protean.utils import Database
from protean.utils.container import id_field, attributes
from protean.utils.container import auto_fields, id_field, attributes
from protean.utils.query import Q

# Global in-memory store of dict data. Keyed by name, to provide
Expand Down Expand Up @@ -258,7 +258,7 @@ def _set_auto_fields(self, model_obj):
"""Set the values of the auto field using counter"""
conn = self._get_session()

for field_name in self.entity_cls.meta_.auto_fields:
for field_name in auto_fields(self.entity_cls):
counter_key = f"{self.schema_name}_{field_name}"
if not (field_name in model_obj and model_obj[field_name] is not None):
# Increment the counter and it should start from 1
Expand Down
8 changes: 0 additions & 8 deletions src/protean/core/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,6 @@ def __init__(self, entity_name, meta):
# Domain Attributes
self.aggregate_cls = getattr(meta, "aggregate_cls", None)

@property
def auto_fields(self):
return {
field_name: field_obj
for field_name, field_obj in self.declared_fields.items()
if isinstance(field_obj, Auto)
}


class _FieldsCacheDescriptor:
def __get__(self, instance, cls=None):
Expand Down
9 changes: 9 additions & 0 deletions src/protean/utils/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import defaultdict

from protean.core.field.base import Field, FieldBase
from protean.core.field.basic import Auto
from protean.exceptions import InvalidDataError, NotSupportedError, ValidationError

logger = logging.getLogger("protean.domain")
Expand Down Expand Up @@ -75,6 +76,14 @@ def unique_fields(class_or_instance):
}


def auto_fields(class_or_instance):
return {
field_name: field_obj
for field_name, field_obj in fields(class_or_instance).items()
if isinstance(field_obj, Auto)
}


class Element:
"""Base class for all Protean elements"""

Expand Down

0 comments on commit aa67f94

Please sign in to comment.