Skip to content

assemble() consumes the census dictionary it is passed #81

Description

@realmarcin

Found reviewing #80, in that PR's own change.

assemble() reads the census run date with census.pop("_as_of"), which removes the key from the caller's dictionary. Calling assemble() twice with the same census object raises KeyError: '_as_of' on the second call.

first call OK; census still has _as_of? False
SECOND CALL FAILS: KeyError '_as_of'

main() loads a fresh dictionary each run, so the shipped path is unaffected. The test suite is not so lucky: FleetPageTests builds self.census once in setUp and test_new_admission_cannot_silently_omit_card_or_graph_node calls render() twice. That test passes today only because its second call raises ValueError from the membership check before reaching the pop. Any reordering of those checks, or any new test that renders twice, turns into a confusing KeyError about a key the author never touched.

A function that takes a parsed document should not consume it. Reading the field and filtering the metadata key out of the Mech entries costs nothing and removes the trap.

Fixing in #80.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions