Skip to content

Copying an EntityList from a loaded blueprint throws InvalidAssociationError if any entities have connections #117

@tephyr

Description

@tephyr

When loading a blueprint from an external source, or building it in code, and then copying its .entities to a Group, Draftsman throws an InvalidAssociationError if any entities have any connections of either kind (circuit or power). The external blueprint is valid in-game, and this can be reproduced in a blueprint with two entities: two power poles with a single electric connection. Test case available as gist.

Current Behavior

  1. Either load an existing blueprint from disk into a Blueprint object, or create one in code.
  2. Copy the blueprint's .entities to a new Group (group.entities.extend(bp.entities)).
  3. IF there are no connections between any entities, the copy will succeed and the group will be ready for use.
  4. If there are connections, an InvalidAssociationError exception will be thrown, with explanatory text like this:

Attempting to connect to <ElectricPole 'medium-02'>{'name': 'medium-electric-pole', 'position': {'x': 3.0, 'y': 0.0}, 'neighbours': [<Association to ElectricPole at 0x00007F62A442FED0>]} which lies outside this EntityCollection; are all Associations between entities contained within this EntityCollection being copied?

Expected behavior
Copying a list of entities from a blueprint should work the same as copying them from a group that was generated in code. All connections should be preserved, and no errors should be thrown.

Additional context
Related to #22.

Draftsman version: 1.1.0
Python version: 3.12.0

I wanted to find out if this can be supported natively, as I use this in a tool that "remixes" blueprints by loading them into Groups and modifying and combining them according to the user's config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionOpen forum; looking for new ideas/inputdocumentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions