Closes #496: Add optional link title to URL fields - #641
Conversation
A url-type CustomObjectTypeField now expands into two real DB columns: the URL itself, and an optional <name>_title used as the visible link text on an object's detail page instead of the raw URL (falling back to the URL when no title is set). Mirrors CoordinatesFieldType's existing two-column pattern, but unlike coordinates the primary URL column keeps behaving like any other single-value column -- unique, default, and regex validation all still apply to it. This required making three previously coordinates-only DDL/validation code paths in models.py dict-aware (the generic single-column schema helpers, the unique-conversion probe in clean(), and the backing- column-collision guard), since URL is the first multi-column type to also flow through the generic single-column path via its unique/ default support. No new migration or upgrade script is needed for existing installations: the plugin's existing post_migrate schema-heal pass already covers any nullable non-mixin column whose attribute name doesn't match a user field's own name, which the new title column satisfies the same way coordinates' latitude/longitude columns already do.
url_scheme_is_allowed() only exists on NetBox's feature branch (added 2026-07-23), not in main or any released version, so importing it broke CI's NetBox-main test matrix leg with an ImportError at plugin load time. This plugin supports NetBox 4.5.2+, well before that function existed. Reimplement the same scheme-allowlist check locally in custom_object_utils.py instead. ALLOWED_URL_SCHEMES itself (the config parameter the function reads) has existed since 2020 and is safe to rely on across the whole supported version range.
|
@claude /review and limit response only to areas of potential concern. |
|
Claude finished @bctiemann's task in 6m 45s —— View job Review: Areas of Potential Concern
1. No tests for
|
- Add tests for get_url_field_html and its security-relevant scheme guard (_url_scheme_is_allowed): allowed scheme with title, allowed scheme falling back to the URL text, a disallowed scheme (e.g. javascript:) rendering as plain text instead of a link, and an unset URL returning ''. - Document that CSV bulk import only populates the URL value, not the title (matches the existing, pre-established limitation for coordinates fields' backing columns). - Make the title column's schema_editor.add_field() call idempotent, checking existing_cols first, matching the established pattern in _schema_add_field() (the URL column already had this guard; the title column's separate add_field() call did not). - Change the title column from CharField(null=True, blank=True) to CharField(blank=True, default=""), so "no title" has one canonical representation instead of two (NULL vs ''). default="" keeps the column eligible for mixin_migration.py's auto-heal pass on existing installations, which requires a column to be nullable or have a Django-level default before auto-adding it.
Summary
Closes: #496
Test plan