-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes #21209: Support real model names in configuration parameters #21275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… configuration Enable DEFAULT_DASHBOARD, CUSTOM_VALIDATORS, and PROTECTION_RULES to accept both lowercase (e.g. "dcim.site") and PascalCase (e.g. "dcim.Site") model names, providing consistency with FIELD_CHOICES. - Update get_models_from_content_types() to normalize model identifiers - Add _get_validators_for_model() helper for case-insensitive config lookup
8c77bf2 to
273750c
Compare
|
Thanks a lot for working on this! 🙌 While reviewing the feature request, I noticed the scope is a bit broader than what’s currently covered in this PR. The request is to allow ContentType/ObjectType strings (e.g.
From what I can see, this PR currently addresses only the Would you mind taking another pass to review the other config paths as well, and extend the PR to include any additional configuration options where these model strings are accepted? |
1a3a76f to
03912fc
Compare
Thanks for the review @pheus! Really appreciate it! 🙌 The PR now covers all three areas mentioned in the FR:
As a bonus, I also updated CUSTOM_VALIDATORS to use the same case-insensitive pattern for consistency. All changes follow the same approach: try an exact match first (O(1)), then fall back to a case-insensitive search if needed. This maintains backward compatibility while allowing users to use either format. The PR is ready for another review. |
jnovinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some notes, but this is a great start. Also, you need to make sure you update the docs (as noted in the PR description).
2dc1c49 to
3d7ab8b
Compare
pheus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pushing this forward! I appreciate that you’re applying it consistently across FIELD_CHOICES and CUSTOM_VALIDATORS.
A few follow-ups I’d like to see addressed
Tests: please add an integration-style test for FIELD_CHOICES casing + + suffix
The unit tests for get_config_value_ci() are helpful, but I’d like to see at least one test that proves:
- replacement works when config key casing differs (e.g.
dcim.Site.status), and - extension works with the
+suffix under casing differences (e.g.dcim.Site.status+).
That will ensure the original reported issue stays fixed and avoids future regressions.
- Create get_config_value_ci() in utilities/data.py - Inline at call sites in extras/signals.py and core/signals.py - Remove get_validators_for_model() wrapper function - Only compute extend_choices if replace_choices is None - Add unit tests for get_config_value_ci() - Add integration tests for FIELD_CHOICES case-insensitive lookup - Update documentation examples to use PascalCase consistently
3d7ab8b to
aa03956
Compare
|
Thanks for the feedback @pheus! Appreciate that. I've added integration tests in
Other comments are also resolved as per the feedback. Ready for your review! :) |
pheus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! I re-reviewed the latest changes.
Nice cleanup 👍
Overall, LGTM — thanks for iterating on this and for adding solid tests.
Thanks a lot for the review @pheus! |
Summary
This PR adds support for real model names (e.g.,
dcim.Site) inDEFAULT_DASHBOARD,CUSTOM_VALIDATORS, andPROTECTION_RULESconfiguration parameters, matching the syntax used byFIELD_CHOICES.Changes:
normalize_model_identifier()utility function to convert real model names to lowercase format used by ObjectTypeget_models_from_content_types()in dashboard widgets to normalize model identifiersCUSTOM_VALIDATORSandPROTECTION_RULESlookups to check both real model names and lowercase namesBackward Compatibility
Both formats are supported:
dcim.Site,ipam.IPAddressdcim.site,ipam.ipaddress(existing behavior preserved)Fixes #21209