Skip to content

Commit 1343ccf

Browse files
committed
Use dtype.from_dataverse_dict for compound fields
Replace the ad-hoc globals/sys.modules lookup of CompoundField with a direct call to `field_info.dtype.from_dataverse_dict` when `field.value` is a dict. This simplifies the code, makes the conversion use the field's declared dtype (more robust and accurate), and removes the fallback import logic.
1 parent ff476d0 commit 1343ccf

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

pyDataverse/dataverse/connect/metadata.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,8 @@ def _process_field(cls, field, field_info):
407407
@classmethod
408408
def _process_compound_field(cls, field, field_info):
409409
"""Process a compound field value."""
410-
# Get CompoundField from module globals (defined later in this module)
411-
CompoundField = globals().get("CompoundField")
412-
if CompoundField is None:
413-
# Fallback: import if not yet defined (shouldn't happen)
414-
import sys
415-
416-
module = sys.modules[__name__]
417-
CompoundField = getattr(module, "CompoundField", None)
418-
419-
if CompoundField is not None and isinstance(field.value, dict):
420-
return CompoundField.from_dataverse_dict(field.value)
410+
if isinstance(field.value, dict):
411+
return field_info.dtype.from_dataverse_dict(field.value)
421412

422413
if isinstance(field.value, list):
423414
return [

0 commit comments

Comments
 (0)