Skip to content

The order of new attributes added to VirtualCodebase is not intuitive #1040

@JonoYang

Description

@JonoYang

I added a new attribute to the Resource class when using VirtualCodebase like so:

        plugin_attributes = dict(matches=attr.ib(default=attr.Factory(list)))
        vc = VirtualCodebase(
            json_scan_location=self.input_file.path,
            plugin_attributes=plugin_attributes
        )

When I add a new attribute to the Resource class when using VirtualCodebase, I expect my new attribute to show up at the end of all the other attributes that already exist from the attributes collected from the input scan file. What happens when I export the codebase to JSON is that the new attribute shows up in front or in the middle of all the other attributes.

It turns out that the attributes classes created by attrs have a counter attribute that dictates attribute order. I worked around this issue by doing this:

        matches = attr.ib(default=attr.Factory(list))
        matches.counter = 50
        plugin_attributes = dict(matches=matches)

        vc = VirtualCodebase(
            json_scan_location=self.input_file.path,
            plugin_attributes=plugin_attributes
        )

Now, the new matches attribute is at the end of all the other attributes, as desired.

It would be nice to have a way to not have to do this workaround when adding new attributes to Resources in a VirtualCodebase.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions