Skip to content

Commit 71c0f4d

Browse files
committed
binding flow fix
1 parent aee6b7d commit 71c0f4d

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

flopy4/mf6/codec/reader/transformer.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ def __default__(self, data, children, meta):
375375
return (data, child)
376376

377377
# Handle keyword rules (no children) - return (name, True)
378-
if not children:
378+
# But not for _fields rules which may legitimately be empty
379+
if not children and not data.endswith("_fields"):
379380
return (data, True)
380381

381382
# Handle block rules (e.g., options_block, dimensions_block)
@@ -405,12 +406,16 @@ def __default__(self, data, children, meta):
405406
elif isinstance(item, tuple):
406407
field_tuples.append(item)
407408

408-
# For binding blocks (models, exchanges, solutiongroup), return just the
409-
# records list. The _block handler will wrap it as {block_name: list},
410-
# which is what the converter expects for binding resolution.
409+
# For binding blocks (models, exchanges, solutiongroup), always return
410+
# a list (possibly empty). The _block handler will wrap it as
411+
# {block_name: list}, which is what the converter expects.
411412
# Note: solutiongroup has mxiter, but we ignore it here since the
412413
# Simulation class doesn't have a place for it yet.
413-
if records and (not field_tuples or block_name == "solutiongroup"):
414+
if block_name in ("models", "exchanges", "solutiongroup"):
415+
return records
416+
417+
# For other blocks with only records (no scalar fields), return list
418+
if records and not field_tuples:
414419
return records
415420

416421
# Build result dict from scalar fields

flopy4/mf6/converter/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ def _resolve_bindings_in_dict(data: dict, workspace: Path, target_type: type) ->
112112
"""
113113
Resolve binding tuples in data dict to component instances.
114114
115-
Detects lists of binding tuples (e.g., [['gwf6', 'file.nam', 'name']])
116-
and transforms them to component instances or dicts of instances.
115+
Detects:
116+
- Lists of binding tuples (e.g., [['gwf6', 'file.nam', 'name']])
117+
- Scalar bindings (e.g., {'tdis6': 'simulation.tdis'})
117118
118119
Parameters
119120
----------
@@ -140,7 +141,18 @@ def _resolve_bindings_in_dict(data: dict, workspace: Path, target_type: type) ->
140141

141142
value = resolved[field_name]
142143

143-
# Skip if not a list (no binding tuples to resolve)
144+
# Handle scalar bindings: {'tdis6': 'filename.tdis'}
145+
# These are dicts with a single key ending in '6'
146+
if isinstance(value, dict) and len(value) == 1:
147+
binding_key = next(iter(value.keys()))
148+
if isinstance(binding_key, str) and binding_key.lower().endswith("6"):
149+
binding_fname = value[binding_key]
150+
binding_tuple = [binding_key, binding_fname]
151+
component = Binding.to_component(binding_tuple, workspace)
152+
resolved[field_name] = component
153+
continue
154+
155+
# Handle list bindings
144156
if not isinstance(value, list):
145157
continue
146158

0 commit comments

Comments
 (0)