Skip to content

fix: correct first element condition in ImportTemplate loops (fixes #358)#409

Open
Cypher-CP0 wants to merge 1 commit intoEAPD-DRB:mainfrom
Cypher-CP0:fix/issue-358-restore
Open

fix: correct first element condition in ImportTemplate loops (fixes #358)#409
Cypher-CP0 wants to merge 1 commit intoEAPD-DRB:mainfrom
Cypher-CP0:fix/issue-358-restore

Conversation

@Cypher-CP0
Copy link
Copy Markdown

Linked issue

Existing related work reviewed

Overlap assessment

  • Classification: Bug fix
  • Overlapping items: None
  • Why this is not duplicate/superseded: No existing PR addresses this bug

Why this PR should proceed

  • Silent logic error causing all imported entities to receive random IDs
    instead of stable base IDs, breaking deterministic model initialization
    and any downstream logic depending on TEC_0, COM_0, EMI_0, STG_0

Summary

  • What changed: Added enumerate() to the four affected loops
    (technologies, commodities, emissions, storages) in ImportTemplate.py
    and replaced obj == 0 with i == 0 in each. Also fixed an incorrect
    default description string "Default commodity" inside the technologies
    loop (line 633).
  • Why: obj is a dictionary, not an integer, so obj == 0 always
    evaluates to False. This meant first=True was never passed,
    so stable base IDs (TEC_0, COM_0, EMI_0, STG_0) were never assigned
    to the first element of each entity type during template import.

Validation

  • Tests added/updated (or not applicable)
  • Validation steps documented
  • Evidence attached (logs/screenshots/output as relevant)

Documentation

  • Docs updated in this PR (or not applicable)
  • Any setup/workflow changes reflected in repo docs

Scope check

  • No unrelated refactors
  • Implemented from a feature branch
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main (not upstream)

Exception rationale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ImportTemplate uses incorrect condition (obj == 0), preventing assignment of stable base IDs

1 participant