Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JonoYang opened this issue Apr 20, 2018 · 2 comments
Closed

Comments

@JonoYang
Copy link
Contributor

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.

@pombredanne pombredanne added this to the v3.0 milestone Nov 5, 2018
@pombredanne
Copy link
Contributor

pombredanne commented Nov 5, 2018

I think this may have been fixed now. This was because of the combo of an attrs bugs and a workaround ... we need to retest that since python-attrs/attrs#339 has been fixed and merged python-attrs/attrs#343

@JonoYang Can you retest this with the latest code?

@JonoYang
Copy link
Contributor Author

JonoYang commented Oct 9, 2019

New attributes are now placed at the bottom without having to resort to workarounds. Closed.

@JonoYang JonoYang closed this as completed Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants