Parser: any class whose base name ends in `Mixin` becomes a model, even a QuerySet or a plain helper
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 25/100
調査の方向性
Start in cli/orm_lens/parser.py: the Mixin$ branch of _looks_like_model() (around line 442) and where _resolve_and_filter() (around line 829) seeds is_model_name from it. Run the repro from the issue to confirm that only projects.Project should be listed. Done when phantom mixins drop out, the abstract-mixin test in test_abstract_and_auth_user.py and the mezzanine golden snapshot still pass, and pytest, ruff and mypy are clean. Note that open pull request #258 already targets this issue, so check it before starting.
索引モデルが issue の本文から書いたものです。
説明
Source: label-studio — label_studio/projects/models.py:72, label_studio/tasks/models.py; weblate — weblate/trans/mixins.py:74,81,154
What happens
_looks_like_model() returns True as soon as a base's name ends with Mixin. That's a guess for third-party bases we can't see. But it also fires when the mixin is defined right there in the workspace and is a plain class:
- label-studio:
class ProjectQuerySetWithFSM(FSMStateQuerySetMixin, ProjectQuerySet).ProjectQuerySetis amodels.QuerySet,FSMStateQuerySetMixinis a plain class. orm-lens listsprojects.ProjectQuerySetWithFSMas a model, anddriftsays blocking: "declared, but no migration creates it". Four of these, sodriftfails the build. - weblate:
class URLMixin(BaseURLMixin),LoggerMixin(BaseURLMixin),PathMixin(LoggerMixin, URLMixin)intrans/mixins.py.BaseURLMixinisclass BaseURLMixin:. They're pulled in becauseProjectinheritsPathMixin, and then show up as three blockingdriftentries.
Repro
projects/mixins.py
class StateQuerySetMixin:
def with_state(self):
return self
class URLMixin:
def get_absolute_url(self):
return "/"
projects/models.py
from django.db import models
from .mixins import StateQuerySetMixin, URLMixin
class ProjectQuerySet(models.QuerySet):
pass
class ProjectQuerySetWithState(StateQuerySetMixin, ProjectQuerySet):
pass
class PathMixin(URLMixin):
def full_path(self):
return self.get_absolute_url()
class Project(models.Model, PathMixin):
title = models.CharField(max_length=100)
objects = ProjectQuerySetWithState.as_manager()
$ orm-lens list
projects.ProjectQuerySetWithState
projects.PathMixin
projects.Project
Expected: only projects.Project.
Where
cli/orm_lens/parser.py
- line 442,
_looks_like_model(), there.search(r"Mixin$", tail)branch; - line 829,
_resolve_and_filter(), which seedsis_model_namefrom_looks_like_model()and then runs the fixed point over real definitions.
Suggested fix
Use the name guess only for bases we have no definition for. In _resolve_and_filter(), collect defined = {m.name for m in all_defs} and pass it to _looks_like_model(); skip the Mixin$ branch when tail in defined. A mixin that really is a model (class TimeStampMixin(models.Model)) still gets in through the fixed-point loop, because its own base is models.Model.
test_abstract_and_auth_user.py covers abstract mixins and should stay green. The mezzanine golden fixture has *Mixin classes too, so run the golden tests and update the snapshot if a phantom model drops out (say so in the PR).
How to test
- A test in
cli/tests/test_cross_module_bases.py(or a new file) with the repro: onlyProjectis returned. - A mixin defined as
class OwnedMixin(models.Model)withabstract = True, plusclass Doc(OwnedMixin):Docis still a model and inherits the fields. cd cli && python -m pytest -q,ruffandmypypass.
Difficulty: good first issue.
- 主要言語
- Python
- スター
- 84
- フォーク
- 13
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FROWNINGdev/django-orm-lens のほかの issue
-
suggest-indexes proposes composite indexes that include the primary key or a unique field対応中かも @bfs2021 が今日担当しました。 オープンbug good first issue python
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
FROWNINGdev/django-orm-lens#269 ·
-
`migration-risk` text output prints `app.None` for graph-level findings対応中かも @phoenixbycaselka が今日担当しました。 オープンbug good first issue python
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
FROWNINGdev/django-orm-lens#268 ·
-
Finish the Chinese rule reference — DOL001–DOL007再び着手できるかも @harbinresearcher が 64 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンdocumentation good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
FROWNINGdev/django-orm-lens#81 · コメント 2 件 ·
-
Fields inherited from Django's `AbstractBaseUser` / `PermissionsMixin` / `AbstractUser` are missingオープンbug good first issue python
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
FROWNINGdev/django-orm-lens#267 ·
-
bug good first issue python
難易度 3/5 半日 初心者へのやさしさ 78/100
FROWNINGdev/django-orm-lens#266 ·
FROWNINGdev/django-orm-lens の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gorakhargosh/watchdog#1462 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
openwisp/openwisp-monitoring#889 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
OpenFreeEnergy/Lomap#180 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
roman-corgi/corgisim#327 ·
メンテナーはふだん 2 日以内に返信
-
agent:WSL bug code-review linux pri:medium sev:low tooling
難易度 2/5 半日 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信