Skip to content

bug: Generator tracking doesn't remove nodes from group if group becomes empty #572

@BaptisteGi

Description

@BaptisteGi

Component

Python SDK

Infrahub SDK version

v1.14.0

Current Behavior

I have a generator that creates objects. In some case this generator could run a second time without creating any object (decommissioning scenario).
=> During this second run objects that are members of the tracking group aren't deleted

Expected Behavior

I expect the generator to delete all objects that are member of the tracking groups if these objects aren't created during the run

Steps to Reproduce

  • Run generator that creates objects
  • Run a second time the same generator but this time it just goes to return

Additional Information

  • If during my second run the generator creates a placeholder tag for instance, other objects in the group are removed. So it's really when the number of member reaches 0.
    async def update_group(self) -> None:
        """
        Create or update (using upsert) a CoreStandardGroup to store all the Nodes and Groups used during an execution.
        """
        members: list[str] = self.related_group_ids + self.related_node_ids

        if not members:
            return

        group_name = self._generate_group_name()
        schema = await self.client.schema.get(kind=self.group_type)
        description = self._generate_group_description(schema=schema)

        existing_group = None
        if self.delete_unused_nodes:
            existing_group = await self.get_group(store_peers=True)

        group = await self.client.create(
            kind=self.group_type,
            name=group_name,
            description=description,
            members=members,
            branch=self.branch,
            **self.group_params,
        )
        await group.save(allow_upsert=True, update_group_context=False)

This is fishy:

        if not members:
            return

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/2This issue stalls work on the project or its dependents, it's a blocker for a releasetype/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions