Skip to content

Commit

Permalink
Don't process internal models twice if imported from project
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Jan 20, 2025
1 parent e095c16 commit 91b2e2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/dipdup/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,15 @@ def prepare_models(package: str | None) -> None:
EXECUTOR_CACHE.clear()

db_tables: set[str] = set()
qualnames: set[str] = set()

for app, model in iter_models(package):
# NOTE: Don't process internal models twice if imported from project
qualname = f'{model.__module__}.{model.__qualname__}'
if qualname in qualnames:
continue
qualnames.add(qualname)

# NOTE: Enforce our class for user models
if app != 'int_models' and not issubclass(model, dipdup.models.Model):
raise InvalidModelsError(
Expand Down
4 changes: 1 addition & 3 deletions src/dipdup/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def __init__(self, max_digits: int, decimal_places: int, **kwargs: Any) -> None:
self.quant = Decimal('1' if decimal_places == 0 else f'1.{("0" * decimal_places)}')

def to_python_value(self, value: Any) -> Decimal | None:
if value is None:
value = None
else:
if value is not None:
value = Decimal(value).quantize(self.quant).normalize()
self.validate(value)
return value # type: ignore[no-any-return]
Expand Down

0 comments on commit 91b2e2f

Please sign in to comment.