Fixes #21213: Make Tag weight field required in forms #531

Closed
opened 2026-04-05 16:40:23 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @adionit7 on 1/19/2026

The weight field was explicitly declared with required=False in TagForm and TagImportForm, allowing empty submissions that would crash with a database IntegrityError since the column is NOT NULL.

By removing the explicit field override, Django now auto-generates the form field from the model, which has default=1000 and is required. This ensures the UI matches the database constraint and prevents invalid submissions before they reach the database.

Fixes: #21213

Summary

  • Remove the explicit weight field overrides from TagForm and TagImportForm that set required=False.
  • Allow Django to use the model’s PositiveSmallIntegerField(default=1000) directly, making the field required at the form level.
  • Align form validation with the database NOT NULL constraint to avoid IntegrityError when the weight is left empty.
*Originally created by @adionit7 on 1/19/2026* The weight field was explicitly declared with `required=False` in `TagForm` and `TagImportForm`, allowing empty submissions that would crash with a database `IntegrityError` since the column is `NOT NULL`. By removing the explicit field override, Django now auto-generates the form field from the model, which has `default=1000` and is required. This ensures the UI matches the database constraint and prevents invalid submissions before they reach the database. <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #21213 <!-- Please include a summary of the proposed changes below. --> ### Summary - Remove the explicit `weight` field overrides from `TagForm` and `TagImportForm` that set `required=False`. - Allow Django to use the model’s `PositiveSmallIntegerField(default=1000)` directly, making the field required at the form level. - Align form validation with the database `NOT NULL` constraint to avoid `IntegrityError` when the weight is left empty.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#531