Skip to content

Commit cbfc94a

Browse files
committed
Don't shortcut this case.
1 parent 326bd43 commit cbfc94a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

.generator/src/generator/templates/model_utils.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,8 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
16241624
return None
16251625

16261626
# Fast path: use type discriminator when all oneOf classes have a unique 'type' value.
1627+
# Pure optimisation — on any failure falls through to the full O(N) scan below so
1628+
# behaviour is identical to the original; never short-circuits to UnparsedObject here.
16271629
if model_arg is None and model_kwargs:
16281630
disc_map = _build_discriminator_map(cls)
16291631
if disc_map is not None:
@@ -1639,7 +1641,6 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
16391641
oneof_instance = oneof_class(**model_kwargs, **constant_kwargs)
16401642
if not oneof_instance._unparsed:
16411643
return oneof_instance
1642-
return UnparsedObject(**model_kwargs)
16431644

16441645
oneof_instances = []
16451646
# Iterate over each oneOf schema and determine if the input data

src/datadog_api_client/model_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,8 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
16361636
return None
16371637

16381638
# Fast path: use type discriminator when all oneOf classes have a unique 'type' value.
1639+
# Pure optimisation — on any failure falls through to the full O(N) scan below so
1640+
# behaviour is identical to the original; never short-circuits to UnparsedObject here.
16391641
if model_arg is None and model_kwargs:
16401642
disc_map = _build_discriminator_map(cls)
16411643
if disc_map is not None:
@@ -1651,7 +1653,6 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None):
16511653
oneof_instance = oneof_class(**model_kwargs, **constant_kwargs)
16521654
if not oneof_instance._unparsed:
16531655
return oneof_instance
1654-
return UnparsedObject(**model_kwargs)
16551656

16561657
oneof_instances = []
16571658
# Iterate over each oneOf schema and determine if the input data

0 commit comments

Comments
 (0)