From 91b2e2f77a05074df3c1c3c5ea0a2b1a5aa9b4a0 Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Mon, 20 Jan 2025 16:07:31 -0300 Subject: [PATCH] Don't process internal models twice if imported from project --- src/dipdup/database.py | 7 +++++++ src/dipdup/fields.py | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dipdup/database.py b/src/dipdup/database.py index 4eabcb493..7870ac11e 100644 --- a/src/dipdup/database.py +++ b/src/dipdup/database.py @@ -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( diff --git a/src/dipdup/fields.py b/src/dipdup/fields.py index ef9403ca1..4eeaebfac 100644 --- a/src/dipdup/fields.py +++ b/src/dipdup/fields.py @@ -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]