Models in a sub-package of an app get the sub-package's label (`io_storages/s3/models.py` → app `s3`)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
The app label is set inline in parse_models_file() in cli/orm_lens/parser.py (around lines 610-614), and the same rule lives in _app_dir_for() in cli/orm_lens/_paths.py. Start by reproducing the io_storages/s3/models.py layout and running orm-lens list and drift, then look at how both call sites derive the app. Done means list shows io_storages.S3ImportStorage, drift reports nothing, the existing shop/ cases keep their labels, and cd cli && python -m pytest -q passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Source: label-studio — label_studio/io_storages/{s3,gcs,azure_blob,redis,localfiles}/models.py
What happens
The app label comes from the directory that holds models.py (or from the parent of a models/ package). That breaks for apps that split models into sub-packages:
io_storages/
apps.py
migrations/
models.py # from .s3.models import S3ImportStorage
s3/models.py # class S3ImportStorage(models.Model)
Django puts S3ImportStorage in io_storages: the label comes from the app config whose package contains the module, not from the file's own directory. orm-lens calls the app s3.
On label-studio list shows s3.S3ImportStorage, gcs.GCSImportStorage and so on, describe io_storages.S3ImportStorage fails, and drift prints 25 "migrated, but models.py does not declare it" lines for io_storages.*.
Repro
io_storages/__init__.py, io_storages/migrations/__init__.py, io_storages/s3/__init__.py: empty.
io_storages/models.py
from .s3.models import S3ImportStorage # noqa: F401
io_storages/s3/models.py
from django.db import models
class S3ImportStorage(models.Model):
bucket = models.TextField(null=True, blank=True)
prefix = models.TextField(null=True, blank=True)
io_storages/migrations/0001_initial.py
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="S3ImportStorage",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
("bucket", models.TextField(null=True, blank=True)),
("prefix", models.TextField(null=True, blank=True)),
],
),
]
$ orm-lens list
s3.S3ImportStorage
$ orm-lens describe io_storages.S3ImportStorage
error: model 'io_storages.S3ImportStorage' not found
$ orm-lens drift
~ io_storages.s3importstorage: migrated, but models.py does not declare it
stale table, or the model lives outside the parsed tree
summary: 1 model(s) drifted, 0 blocking, 1 migration(s) replayed
Expected: io_storages.S3ImportStorage, no drift.
Where
cli/orm_lens/parser.py, lines 610–614 inparse_models_file()(line 498): setsapp_namefrom the parent directory, or the grandparent formodels/.cli/orm_lens/_paths.py, line 21,_app_dir_for(): the same rule, used to group models into apps (parser.py:1191) and to pick a base class in the same app (parser.py:826). Both have to agree.
Suggested fix
Put the lookup in _app_dir_for() and use it from parse_models_file() too, instead of the inline copy:
- Start at the directory of the file (or the parent of a
models/package, as now). - If that directory has
migrations/orapps.py, it's the app. - Otherwise go up while the parent is still a package (has
__init__.py) and stop at the first directory that hasmigrations/orapps.py. - Nothing found: today's rule.
The __init__.py check keeps the walk inside the project. Meta.app_label is a separate case, leave it out.
src/parser.ts has the same rule (around lines 380 and 632). A Python-only fix is fine, leave a note in the PR for the TS side.
How to test
- A new test with the repro:
listgivesio_storages.S3ImportStorage,driftreports nothing. - A plain app (
shop/models.py) and amodels/package (shop/models/order.py) keep their labels. - A
models.pyin a folder with nomigrations/orapps.pyabove it keeps today's label. - Run the golden snapshots. If a project changes, update it and list the changes in the PR.
cd cli && python -m pytest -q,ruffandmypypass.
Difficulty: good first issue, one helper and a few tests.
- Ngôn ngữ chính
- Python
- Star
- 84
- Fork
- 13
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FROWNINGdev/django-orm-lens
-
suggest-indexes proposes composite indexes that include the primary key or a unique fieldCó thể đã có người làm @bfs2021 đã nhận hôm nay. Đang mởbug good first issue python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
FROWNINGdev/django-orm-lens#269 ·
-
`migration-risk` text output prints `app.None` for graph-level findingsCó thể đã có người làm @phoenixbycaselka đã nhận hôm nay. Đang mởbug good first issue python
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
FROWNINGdev/django-orm-lens#268 ·
-
Finish the Chinese rule reference — DOL001–DOL007Có thể làm lại được @harbinresearcher đã nhận 64 ngày trước và không có pull request nào đang mở. Đang mởdocumentation good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
FROWNINGdev/django-orm-lens#81 · 2 bình luận ·
-
Fields inherited from Django's `AbstractBaseUser` / `PermissionsMixin` / `AbstractUser` are missingĐang mởbug good first issue python
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
FROWNINGdev/django-orm-lens#267 ·
-
enhancement help wanted python
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FROWNINGdev/django-orm-lens#254 ·
Tất cả issue của FROWNINGdev/django-orm-lens
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gorakhargosh/watchdog#1462 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
openwisp/openwisp-monitoring#889 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenFreeEnergy/Lomap#180 ·
-
generate_observation_scenario_from_cpgs exposure time conversion when auto-gain set to 'yes'Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
roman-corgi/corgisim#327 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
agent:WSL bug code-review linux pri:medium sev:low tooling
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày