django-orm-lens 1.2.4__tar.gz → 1.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/PKG-INFO +1 -1
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/parser.py +9 -1
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/PKG-INFO +1 -1
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/SOURCES.txt +1 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/pyproject.toml +1 -1
- django_orm_lens-1.2.5/tests/test_aliased_module_and_third_party_fields.py +94 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/README.md +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/__init__.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/cli.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/diff.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/formatters.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/mcp_server.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/migrations_parser.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/models.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/py.typed +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/query_analyzer.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens/signals_parser.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/dependency_links.txt +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/entry_points.txt +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/requires.txt +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/top_level.txt +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/setup.cfg +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_abstract_and_auth_user.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_cli_hint.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_cli_subcommands_smoke.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_cli_verbose.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_cross_module_bases.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_diff_command.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_golden_fixtures.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_kwarg_order_and_auth_user.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_list_command.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_migration_risk.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_migrations_parser.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_nplusone_detector.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_parity.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_pep526_type_hints.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_pep695_generic_classes.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_query_analyzer.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_scan_root.py +0 -0
- {django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/tests/test_signals_parser.py +0 -0
|
@@ -135,12 +135,20 @@ def _build_body_regexes(indent: int):
|
|
|
135
135
|
# ``[^=]+`` is safe because ``=`` never appears inside a type expression
|
|
136
136
|
# (subscripts, unions, dotted refs, and generics all use other punctuation).
|
|
137
137
|
ann = r"(?:\s*:[^=]+)?"
|
|
138
|
+
# ``(?:[A-Za-z_][A-Za-z0-9_]*\.)?`` — optional single-identifier prefix on
|
|
139
|
+
# the RHS. Covers:
|
|
140
|
+
# * aliased models module — ``from django.db import models as m; x = m.CharField(...)``
|
|
141
|
+
# * third-party field packages — ``x = jsonfield.JSONField(default=dict)``
|
|
142
|
+
# * standard bare imports — ``from django.db.models import CharField; x = CharField(...)``
|
|
143
|
+
# Safe against false positives because the type name is still restricted
|
|
144
|
+
# to Django's known field whitelist (BARE_FIELD_TYPES).
|
|
145
|
+
prefix_opt = r"(?:[A-Za-z_][A-Za-z0-9_]*\.)?"
|
|
138
146
|
result = {
|
|
139
147
|
"FIELD_RE": re.compile(
|
|
140
148
|
rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*models\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
|
|
141
149
|
),
|
|
142
150
|
"BARE_FIELD_RE": re.compile(
|
|
143
|
-
rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*({BARE_FIELD_TYPES})\s*\("
|
|
151
|
+
rf"^{w}([a-zA-Z_][a-zA-Z0-9_]*){ann}\s*=\s*{prefix_opt}({BARE_FIELD_TYPES})\s*\("
|
|
144
152
|
),
|
|
145
153
|
"META_START_RE": re.compile(rf"^{w}class\s+Meta\s*(?:\([^)]*\))?\s*:"),
|
|
146
154
|
"META_ITEM_RE": re.compile(
|
|
@@ -18,6 +18,7 @@ django_orm_lens.egg-info/entry_points.txt
|
|
|
18
18
|
django_orm_lens.egg-info/requires.txt
|
|
19
19
|
django_orm_lens.egg-info/top_level.txt
|
|
20
20
|
tests/test_abstract_and_auth_user.py
|
|
21
|
+
tests/test_aliased_module_and_third_party_fields.py
|
|
21
22
|
tests/test_cli_hint.py
|
|
22
23
|
tests/test_cli_subcommands_smoke.py
|
|
23
24
|
tests/test_cli_verbose.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "django-orm-lens"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.5"
|
|
8
8
|
description = "Static analysis + MCP server for Django models. Sidebar tree, ER diagrams, and JSON output for terminals and AI coding agents."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Regression tests for two field-detection gaps surfaced by targeted fuzz:
|
|
2
|
+
|
|
3
|
+
1. **Aliased models module.** ``from django.db import models as m`` followed
|
|
4
|
+
by ``class X(m.Model): x = m.CharField(...)`` used to lose every field
|
|
5
|
+
because ``FIELD_RE`` hardcoded the ``models\\.`` prefix and
|
|
6
|
+
``BARE_FIELD_RE`` had no prefix allowance at all.
|
|
7
|
+
|
|
8
|
+
2. **Third-party field packages.** Fields declared via a namespaced
|
|
9
|
+
third-party import - ``x = jsonfield.JSONField(default=dict)``,
|
|
10
|
+
``x = timezonefield.TimeZoneField()`` - also fell through the same
|
|
11
|
+
two-way gap.
|
|
12
|
+
|
|
13
|
+
Fixed by adding an optional single-identifier prefix on the RHS in
|
|
14
|
+
``BARE_FIELD_RE``. Safe against false positives because the type name
|
|
15
|
+
is still restricted to Django's known field whitelist
|
|
16
|
+
(``BARE_FIELD_TYPES``) - random ``foo.CharField(...)`` calls in
|
|
17
|
+
non-Django code won't leak in unless the trailing name is a real
|
|
18
|
+
Django field type.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import unittest
|
|
24
|
+
|
|
25
|
+
from django_orm_lens.parser import parse_models_file
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AliasedModelsModuleTest(unittest.TestCase):
|
|
29
|
+
def test_all_fields_captured_via_alias(self) -> None:
|
|
30
|
+
src = (
|
|
31
|
+
"from django.db import models as m\n\n"
|
|
32
|
+
"class Order(m.Model):\n"
|
|
33
|
+
" status = m.CharField(max_length=20)\n"
|
|
34
|
+
" total = m.DecimalField(max_digits=10, decimal_places=2)\n"
|
|
35
|
+
" quantity = m.IntegerField(default=1)\n"
|
|
36
|
+
)
|
|
37
|
+
models = parse_models_file("shop/models.py", src)
|
|
38
|
+
self.assertEqual(len(models), 1)
|
|
39
|
+
self.assertEqual(models[0].name, "Order")
|
|
40
|
+
self.assertEqual(
|
|
41
|
+
[f.name for f in models[0].fields],
|
|
42
|
+
["status", "total", "quantity"],
|
|
43
|
+
)
|
|
44
|
+
self.assertEqual(models[0].fields[0].type, "CharField")
|
|
45
|
+
|
|
46
|
+
def test_mixed_alias_and_plain_and_bare(self) -> None:
|
|
47
|
+
# One model, three import styles interleaved - every field must
|
|
48
|
+
# be captured regardless of prefix.
|
|
49
|
+
src = (
|
|
50
|
+
"from django.db import models as m\n"
|
|
51
|
+
"from django.db.models import IntegerField\n\n"
|
|
52
|
+
"class Row(m.Model):\n"
|
|
53
|
+
" aliased = m.CharField(max_length=10)\n"
|
|
54
|
+
" plain = models.TextField()\n"
|
|
55
|
+
" bare = IntegerField(default=0)\n"
|
|
56
|
+
)
|
|
57
|
+
models = parse_models_file("t/models.py", src)
|
|
58
|
+
self.assertEqual(
|
|
59
|
+
[f.name for f in models[0].fields],
|
|
60
|
+
["aliased", "plain", "bare"],
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ThirdPartyFieldPackageTest(unittest.TestCase):
|
|
65
|
+
def test_jsonfield_style_package(self) -> None:
|
|
66
|
+
# `django-jsonfield`-style: `x = jsonfield.JSONField(default=dict)`.
|
|
67
|
+
# JSONField is in the standard whitelist, so this must match even
|
|
68
|
+
# under a non-`models.` prefix.
|
|
69
|
+
src = (
|
|
70
|
+
"import jsonfield\n\n"
|
|
71
|
+
"class Config(models.Model):\n"
|
|
72
|
+
" data = jsonfield.JSONField(default=dict)\n"
|
|
73
|
+
)
|
|
74
|
+
models = parse_models_file("t/models.py", src)
|
|
75
|
+
self.assertEqual([f.name for f in models[0].fields], ["data"])
|
|
76
|
+
self.assertEqual(models[0].fields[0].type, "JSONField")
|
|
77
|
+
|
|
78
|
+
def test_plain_bare_import_still_works(self) -> None:
|
|
79
|
+
# Backward-compat: the pre-fix bare form (no prefix at all) must
|
|
80
|
+
# still match - the prefix is truly optional, not required.
|
|
81
|
+
src = (
|
|
82
|
+
"from django.db.models import CharField, IntegerField\n\n"
|
|
83
|
+
"class R(models.Model):\n"
|
|
84
|
+
" name = CharField(max_length=50)\n"
|
|
85
|
+
" count = IntegerField(default=0)\n"
|
|
86
|
+
)
|
|
87
|
+
models = parse_models_file("t/models.py", src)
|
|
88
|
+
self.assertEqual(
|
|
89
|
+
[f.name for f in models[0].fields], ["name", "count"]
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_orm_lens-1.2.4 → django_orm_lens-1.2.5}/django_orm_lens.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|