Skip to content

Conversation

@adionit7
Copy link
Contributor

Summary

This PR adds support for real model names (e.g., dcim.Site) in DEFAULT_DASHBOARD, CUSTOM_VALIDATORS, and PROTECTION_RULES configuration parameters, matching the syntax used by FIELD_CHOICES.

Changes:

  • Add normalize_model_identifier() utility function to convert real model names to lowercase format used by ObjectType
  • Update get_models_from_content_types() in dashboard widgets to normalize model identifiers
  • Update CUSTOM_VALIDATORS and PROTECTION_RULES lookups to check both real model names and lowercase names
  • Update documentation with real model name examples and backward compatibility notes

Backward Compatibility

Both formats are supported:

  • Real model names: dcim.Site, ipam.IPAddress
  • Lowercase names: dcim.site, ipam.ipaddress (existing behavior preserved)

Fixes #21209

… 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
@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 8c77bf2 to 273750c Compare January 23, 2026 12:25
@pheus
Copy link
Contributor

pheus commented Jan 23, 2026

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. dcim.Device) to be case-insensitive across all relevant configuration parameters. The FR author specifically called out three areas:

  • PROTECTION_RULES
  • DEFAULT_DASHBOARD
  • FIELD_CHOICES

From what I can see, this PR currently addresses only the PROTECTION_RULES and the DEFAULT_DASHBOARD case.

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?

@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 1a3a76f to 03912fc Compare January 23, 2026 13:41
@adionit7
Copy link
Contributor Author

adionit7 commented Jan 23, 2026

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. dcim.Device) to be case-insensitive across all relevant configuration parameters. The FR author specifically called out three areas:

  • PROTECTION_RULES
  • DEFAULT_DASHBOARD
  • FIELD_CHOICES

From what I can see, this PR currently addresses only the PROTECTION_RULES and the DEFAULT_DASHBOARD case.

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?

Thanks for the review @pheus! Really appreciate it! 🙌
You're right.. we initially missed FIELD_CHOICES. I've added case-insensitive support for it in utilities/choices.py using the same pattern.

The PR now covers all three areas mentioned in the FR:

  • DEFAULT_DASHBOARD — accepts both dcim.site and dcim.Site
  • PROTECTION_RULES — case-insensitive lookup via helper function
  • FIELD_CHOICES — case-insensitive lookup for both dcim.Site.status and dcim.site.status (and the + extension variant)

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.

@pheus pheus requested review from a team and jnovinger and removed request for a team January 23, 2026 16:57
Copy link
Member

@jnovinger jnovinger left a 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).

@adionit7 adionit7 requested a review from jnovinger January 27, 2026 01:05
@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 2dc1c49 to 3d7ab8b Compare January 27, 2026 01:06
@adionit7 adionit7 requested a review from pheus January 28, 2026 09:50
Copy link
Contributor

@pheus pheus left a 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
@adionit7 adionit7 force-pushed the 21209-real-model-names branch from 3d7ab8b to aa03956 Compare January 29, 2026 16:25
@adionit7
Copy link
Contributor Author

Thanks for the feedback @pheus! Appreciate that.

I've added integration tests in test_choices.py that verify:

  • Replacement works when config key casing differs (lowercase config key utilities.teststatus found when code looks up PascalCase utilities.TestStatus)
  • Extension works with + suffix under casing differences.

Other comments are also resolved as per the feedback. Ready for your review! :)

@adionit7 adionit7 requested a review from pheus January 29, 2026 16:34
Copy link
Contributor

@pheus pheus left a 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.

@pheus pheus dismissed jnovinger’s stale review January 30, 2026 12:42

Taking over review from jnovinger

@pheus pheus removed the request for review from jnovinger January 30, 2026 12:43
@pheus pheus merged commit bec5ecf into netbox-community:main Jan 30, 2026
7 checks passed
@adionit7
Copy link
Contributor Author

adionit7 commented Jan 30, 2026

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!
Happy to help :)

@adionit7 adionit7 deleted the 21209-real-model-names branch January 30, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use real model names in dashboard widget and other configurations

3 participants