Skip to content

Commit 4181b86

Browse files
committed
Fix CreateLabelForLabelsetMutation: drop None args so model defaults apply
The mutation passed every optional argument (description, color, icon, label_type) through to AnnotationLabel.objects.create() unconditionally. When the caller omitted any of them, the GraphQL kwarg defaulted to None, which Django passes to the INSERT verbatim — bypassing the field-level default. The new NOT NULL on description (and existing NOT NULL/default on color/icon/text) then raised an IntegrityError at INSERT time and the catch-all returned 'Failed to create label for labelset'. Now we filter None values before passing to .create() so model defaults apply.
1 parent 131dd13 commit 4181b86

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

config/graphql/label_mutations.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,21 @@ def mutate(
251251
# Generic deny path — same message and code path as not-found
252252
raise LabelSet.DoesNotExist()
253253
logger.debug("CreateLabelForLabelsetMutation - mutate / Labelset", labelset)
254+
# Drop None values so model field defaults apply (description,
255+
# color, icon, text are NOT NULL with sensible defaults).
256+
create_kwargs = {
257+
k: v
258+
for k, v in {
259+
"text": text,
260+
"description": description,
261+
"color": color,
262+
"icon": icon,
263+
"label_type": label_type,
264+
}.items()
265+
if v is not None
266+
}
254267
obj = AnnotationLabel.objects.create(
255-
text=text,
256-
description=description,
257-
color=color,
258-
icon=icon,
259-
label_type=label_type,
260-
creator=info.context.user,
268+
creator=info.context.user, **create_kwargs
261269
)
262270
obj_id = to_global_id("AnnotationLabelType", obj.id)
263271
logger.debug("CreateLabelForLabelsetMutation - mutate / Created label", obj)

0 commit comments

Comments
 (0)