Skip to content

Commit f9f3a66

Browse files
Fix package model detection (#575)
1 parent 929ab72 commit f9f3a66

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].
66

7+
## [Unreleased]
8+
9+
### Fixed
10+
11+
- models: Fixed package model detection.
12+
713
## [6.4.0] - 2022-12-20
814

915
### Fixed
@@ -15,7 +21,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
1521

1622
## [6.4.0rc1] - 2022-12-09
1723

18-
## Added
24+
### Added
1925

2026
- config: Added optional `code_hash` field to contract config.
2127
- context: Added `first_level` and `last_level` arguments to `ctx.add_index` methods.

docs/deployment/docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DipDup provides multiple prebuilt images for different environments hosted on [D
99
| base image | `python:3.10-slim` | `python:3.10-slim` | `python:3.10-alpine` |
1010
| platforms | `amd64`, `arm64` | `amd64`, `arm64` | `amd64`, `arm64` |
1111
| latest tag | `{{ cookiecutter.dipdup_version }}` | `{{ cookiecutter.dipdup_version }}-pytezos` | `{{ cookiecutter.dipdup_version }}-slim` |
12-
| image size | 352M | 481M | 136M | <!-- TODO: Possibly outdated -->
12+
| image size | 356M | 476M | 139M |
1313
| `dipdup init` command ||||
1414
| `git` and `poetry` included ||||
1515
| PyTezos included | ❌ | ✅ | ❌

src/dipdup/utils/database.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ def is_model_class(obj: Any) -> bool:
9191
"""Is subclass of tortoise.Model, but not the base class"""
9292
from dipdup.models import Model
9393

94-
return isinstance(obj, type) and issubclass(obj, TortoiseModel) and obj not in (TortoiseModel, Model)
94+
if not isinstance(obj, type):
95+
return False
96+
if not issubclass(obj, TortoiseModel):
97+
return False
98+
if obj in (TortoiseModel, Model):
99+
return False
100+
if obj._meta.abstract:
101+
return False
102+
return True
95103

96104

97105
def iter_models(package: Optional[str]) -> Iterator[tuple[str, Type[TortoiseModel]]]:
@@ -114,8 +122,6 @@ def iter_models(package: Optional[str]) -> Iterator[tuple[str, Type[TortoiseMode
114122

115123
attr_value = getattr(module, attr)
116124
if is_model_class(attr_value):
117-
if getattr(getattr(attr_value, 'Meta', None), 'abstract', False):
118-
continue
119125
yield app, attr_value
120126

121127

tests/replays/c0fda4857a03b944f0d9363fb906fbe3d6c0498c4d53a490a2e08288d1014fd2

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dipdup.transactions import TransactionManager
88
from dipdup.utils import pascal_to_snake
99
from dipdup.utils import snake_to_pascal
10+
from dipdup.utils.database import iter_models
1011
from dipdup.utils.database import tortoise_wrapper
1112

1213

@@ -62,3 +63,11 @@ async def test_humps_helpers() -> None:
6263
assert snake_to_pascal('foobar') == 'Foobar'
6364
assert snake_to_pascal('foo__bar') == 'FooBar'
6465
assert snake_to_pascal('FOOBAR') == 'Foobar'
66+
67+
68+
async def test_iter_models() -> None:
69+
models = list(iter_models('demo_token'))
70+
assert len(models) == 8
71+
assert models[0][0] == 'int_models'
72+
assert models[-1][0] == 'models'
73+

0 commit comments

Comments
 (0)