fix: ebios workshop 3 sort by entity name is broken#4081
Conversation
This reverts commit afcccb0.
avoids having to instantiate CustomOrderingFilter every time
📝 WalkthroughWalkthroughThis PR refactors the ordering filter mechanism across the backend, replacing a specialized folder filter with a generalized ChangesOrdering Filter Refactoring & Display Simplification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
backend/core/views.py (1)
743-743: 💤 Low value
lstrip("-")strips all leading dashes; preferremoveprefix("-").
order.lstrip("-")removes every leading"-"character, so a hypothetical"--field"becomes"field"instead of"-field". While DRF only produces single-dash prefixes in practice,str.removeprefix("-")(Python 3.9+, available on this project's 3.14 baseline) is semantically exact.♻️ Proposed refactor
- field_name = order.lstrip("-") + field_name = order.removeprefix("-")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/core/views.py` at line 743, Replace the use of str.lstrip in the sorting/ordering logic so only a single leading dash is removed; in the code that sets field_name = order.lstrip("-") (in backend/core/views.py), change to use order.removeprefix("-") to remove exactly one leading "-" and preserve strings like "--field" as "-field"; ensure the surrounding logic that checks for descending order still inspects the original order string and that this change is compatible with the project's Python 3.14 baseline.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/core/views.py`:
- Around line 714-723: The docstring and class attribute are misleading because
CustomOrderingFilter.get_ordering inspects the view class MRO
(type(view).__mro__), so ordering_mapping must be defined on the view, not on a
filter subclass; update the docstring example to show placing ordering_mapping
on the view class (not on CustomOrderingFilter), remove or deprecate the
ordering_mapping: dict[str, str] = {} attribute from CustomOrderingFilter, and
ensure any tests/examples reference the view's ordering_mapping rather than a
filter subclass; keep references to CustomOrderingFilter and get_ordering so
reviewers can locate the change.
---
Nitpick comments:
In `@backend/core/views.py`:
- Line 743: Replace the use of str.lstrip in the sorting/ordering logic so only
a single leading dash is removed; in the code that sets field_name =
order.lstrip("-") (in backend/core/views.py), change to use
order.removeprefix("-") to remove exactly one leading "-" and preserve strings
like "--field" as "-field"; ensure the surrounding logic that checks for
descending order still inspects the original order string and that this change
is compatible with the project's Python 3.14 baseline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5c449377-fab9-4514-a19b-276af3c13efc
📒 Files selected for processing (3)
backend/core/views.pybackend/ebios_rm/views.pyfrontend/src/lib/components/ModelTable/field/UserGroupNameDisplay.svelte
|
This approach will be abandoned, traceability problem. The suggested approach would be to keep a custom OrderingFilter that checks for foreign keys if a field |
Fixes the sort by entity in Ebios RM, workshop 3, activity 1
Introduces a new
CustomOrderingFilterthat goes with anordering_mappingfield that can map the api call name to it's proper model field before applying the backend ordering. Useful for ordering on more complex fields.Summary by CodeRabbit
New Features
Improvements