Skip to content

Commit 2dafb57

Browse files
MintsIncclaude
andauthored
fix(generator): nullable inline object schema crashes on nil value (DataDog#3976)
When a BDD scenario sends null for a nullable field whose schema is an inline object (no \$ref), reference_to_value raised NotImplementedError because it tried to look up a NewNullableXxx function that doesn't exist for anonymous types. Since nil doesn't need wrapping, return it directly. Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f012d5 commit 2dafb57

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

.generator/src/generator/formatter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ def reference_to_value(schema, value, print_nullable=True, **kwargs):
268268
if nullable:
269269
function_name = schema_name(schema)
270270
if function_name is None:
271+
if value == "nil":
272+
return "nil"
271273
raise NotImplementedError(f"nullable {schema} is not supported")
272274
return formatter.format(prefix=prefix, function_name=function_name, value=value)
273275
return f"&{value}"

.generator/tests/test_formatter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ def test_named_typed_additional_properties_as_array_item_generates_typed_map_sli
8383
result = format_data_with_schema([{"k": "v"}], array_schema)
8484
assert "StringMapItem" not in result
8585
assert "map[string]string" in result
86+
87+
88+
class TestNullableInlineObjectWithNullValue:
89+
"""Nullable inline (anonymous) object schemas must return 'nil' when data is None."""
90+
91+
def test_nullable_inline_object_returns_nil(self):
92+
schema = {"type": "object", "nullable": True}
93+
assert format_data_with_schema(None, schema) == "nil"
94+
95+
def test_nullable_inline_object_with_additional_properties_returns_nil(self):
96+
schema = {"type": "object", "nullable": True, "additionalProperties": {}}
97+
assert format_data_with_schema(None, schema) == "nil"

0 commit comments

Comments
 (0)