Skip to content

Commit 5d25d8a

Browse files
DragnEmperornemesifier
authored andcommitted
[fix] Added "default" kwarg for unique nullable fields
Signed-off-by: DragnEmperor <[email protected]>
1 parent 3348080 commit 5d25d8a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

openwisp_controller/pki/api/serializers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ class Meta:
7373
]
7474
read_only_fields = ["created", "modified"]
7575
extra_kwargs = {
76-
"organization": {"required": True},
76+
# In DRF 3.16+, nullable fields that are part of a unique constraint
77+
# automatically get `default: None`, which can cause validation issues.
78+
# Setting the default to `serializers.empty` ensures DRF does not treat
79+
# these fields as both required and having a default value, avoiding
80+
# conflicts.
81+
"organization": {"required": True, "default": serializers.empty},
7782
"common_name": {"default": "", "required": False},
7883
"key_length": {"initial": "2048"},
7984
"digest": {"initial": "sha256"},

0 commit comments

Comments
 (0)