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

Unable to chain Collection filters #394

Closed
russellballestrini opened this issue Dec 10, 2015 · 2 comments
Closed

Unable to chain Collection filters #394

russellballestrini opened this issue Dec 10, 2015 · 2 comments
Labels
bug This issue is a confirmed bug.

Comments

@russellballestrini
Copy link

I'm following this guide: http://boto3.readthedocs.org/en/latest/guide/collections.html#chainability

It appears that a Collection cannot be filtered like a CollectionManager, even though it has a filter method.

>>> evpc.vpc.instances
ec2.Vpc.instancesCollectionManager(ec2.Vpc(id='vpc-xxxxxx57'), ec2.Instance)

>>> evpc.vpc.instances.filter()
ec2.Vpc.instancesCollection(ec2.Vpc(id='vpc-xxxxxx57'), ec2.Instance)

>>> evpc.vpc.instances.filter().filter(Filter=name_tag_filter('*web*'))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/rballestrini/env/lib/python2.7/site-packages/boto3/resources/collection.py", line 462, in filter
    return CollectionManager.filter(self, **kwargs)
TypeError: unbound method filter() must be called with CollectionManager instance as first argument (got ec2.Vpc.
instancesCollection instance instead)
@kyleknap
Copy link
Contributor

Hmm. I'm seeing an issue as well, but not the same error as you are getting. I am getting instead:
AttributeError: 'ec2.instancesCollection' object has no attribute 'iterator' when I try to chain. Looks like a regression though. If you install version 1.2.1, you should not see the problem anymore.

@kyleknap kyleknap added bug This issue is a confirmed bug. confirmed labels Dec 10, 2015
@kyleknap
Copy link
Contributor

This is just a note for myself:

The code breaks on double chaining because in the CollectionFactory class we assume that we always proxy through the CollectionManager class, but in double chaining we actually store a runtime-generated resource class based from CollectionResource that is used to instantiate the collection, but those collections are using the methods that were attached to the CollectionManager class that we generated at run-time, which even though they have a different interface, they differ in implentation (i.e. no iterator() method existing).

This should not be hard to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants