Fix: plain-admin view URL methods duplicated 5x instead of declared on AdminView base - #122
Open
pullapprove5[bot] wants to merge 1 commit into
Open
Fix: plain-admin view URL methods duplicated 5x instead of declared on AdminView base#122pullapprove5[bot] wants to merge 1 commit into
pullapprove5[bot] wants to merge 1 commit into
Conversation
…n AdminView base
Finding confirmed and fixed. plain-admin/plain/admin/views/objects.py duplicated identical `get_list_url`/`get_create_url`/`get_detail_url`/`get_update_url`/`get_delete_url` `return ""` stubs across 5 AdminView subclasses (25 copies of 5 methods), and viewsets.py/registry.py carried 7 `# ty: ignore` comments only because AdminViewset.get_views() was typed to return `list[type[View]]` (the framework base View) instead of `list[type[AdminView]]`, and registry.py's `register_view` TypeVar `T` was unbound.
Reproduced by stripping the 7 `# ty: ignore` comments from viewsets.py/registry.py and running `uv run ty check plain-admin` (had to `pip install --user uv` first since it wasn't on PATH in this sandbox) — got exactly 7 diagnostics: 6 `unresolved-attribute` in viewsets.py (`viewset`, `get_list_url`, `get_create_url`, `get_detail_url`, `get_update_url`, `get_delete_url` on `type[View[Response]]`) plus 1 `invalid-argument-type` in registry.py:44 (`set.add` expecting `type[AdminView]`, got `type[T@register_view]`). Restored the ignores and confirmed baseline is clean, masking the issue.
Fix: declared the five `get_*_url` methods directly on `AdminView` (base.py), deleted all 25 duplicate stubs from objects.py, changed `AdminViewset.get_views()` to iterate/return `list[type[AdminView]]` (checking `issubclass(attr, AdminView)` instead of the framework's `View`), and bound registry.py's `TypeVar("T")` to `AdminView` (needed for the 7th ignore — `register_view`'s generic `T` was unbound, so even after fixing `get_views()`'s return type, `self.registered_views.add(view)` still failed under `ty` until `T` had an upper bound). Removed all 7 `# ty: ignore` comments; none remain in the touched files (one pre-existing, unrelated ignore remains in models.py, out of scope).
Verified the flip: same `uv run ty check plain-admin` command that produced 7 diagnostics on the pre-fix tree (with ignores stripped) now reports "All checks passed!" on the fixed tree with real ignores permanently removed (not just re-added). Also ran `./scripts/fix plain-admin` (ruff, oxlint/oxfmt, prettier) and `uv run plain-code check plain-admin` (ruff, ty, oxlint, annotation coverage) — all clean.
Could not run `./scripts/test plain-admin` or `./scripts/test`: the suite requires a Postgres database via `scripts/start-postgres`, which falls back to Docker or a local Postgres on 5432, and neither is available in this sandbox (`docker info` fails, port 5432 refuses connections, and `apt-get install postgresql` 404s on the mirror for the required packages). No behavioral/runtime test coverage could be exercised for this change; static analysis (ty/ruff/oxlint) is what's verified here. The change is a pure type/structure refactor (moving identical method bodies up the class hierarchy) with no behavioral change, so this risk is low, but it's an honest gap in verification.
Author
PENDING: 1 review scope pending, 1 agent approved
✅ codex approved Next steps:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finding confirmed and fixed. plain-admin/plain/admin/views/objects.py duplicated identical
get_list_url/get_create_url/get_detail_url/get_update_url/get_delete_urlreturn ""stubs across 5 AdminView subclasses (25 copies of 5 methods), and viewsets.py/registry.py carried 7# ty: ignorecomments only because AdminViewset.get_views() was typed to returnlist[type[View]](the framework base View) instead oflist[type[AdminView]], and registry.py'sregister_viewTypeVarTwas unbound.Reproduced by stripping the 7
# ty: ignorecomments from viewsets.py/registry.py and runninguv run ty check plain-admin(had topip install --user uvfirst since it wasn't on PATH in this sandbox) — got exactly 7 diagnostics: 6unresolved-attributein viewsets.py (viewset,get_list_url,get_create_url,get_detail_url,get_update_url,get_delete_urlontype[View[Response]]) plus 1invalid-argument-typein registry.py:44 (set.addexpectingtype[AdminView], gottype[T@register_view]). Restored the ignores and confirmed baseline is clean, masking the issue.Fix: declared the five
get_*_urlmethods directly onAdminView(base.py), deleted all 25 duplicate stubs from objects.py, changedAdminViewset.get_views()to iterate/returnlist[type[AdminView]](checkingissubclass(attr, AdminView)instead of the framework'sView), and bound registry.py'sTypeVar("T")toAdminView(needed for the 7th ignore —register_view's genericTwas unbound, so even after fixingget_views()'s return type,self.registered_views.add(view)still failed undertyuntilThad an upper bound). Removed all 7# ty: ignorecomments; none remain in the touched files (one pre-existing, unrelated ignore remains in models.py, out of scope).Verified the flip: same
uv run ty check plain-admincommand that produced 7 diagnostics on the pre-fix tree (with ignores stripped) now reports "All checks passed!" on the fixed tree with real ignores permanently removed (not just re-added). Also ran./scripts/fix plain-admin(ruff, oxlint/oxfmt, prettier) anduv run plain-code check plain-admin(ruff, ty, oxlint, annotation coverage) — all clean.Could not run
./scripts/test plain-adminor./scripts/test: the suite requires a Postgres database viascripts/start-postgres, which falls back to Docker or a local Postgres on 5432, and neither is available in this sandbox (docker infofails, port 5432 refuses connections, andapt-get install postgresql404s on the mirror for the required packages). No behavioral/runtime test coverage could be exercised for this change; static analysis (ty/ruff/oxlint) is what's verified here. The change is a pure type/structure refactor (moving identical method bodies up the class hierarchy) with no behavioral change, so this risk is low, but it's an honest gap in verification.Opened by a PullApprove implementation run (implement-finding v4) for:
Merging this is what closes them as fixed.