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

create_tags backtraces when multiples tags are passed #137

Closed
iMilnb opened this issue Jun 18, 2015 · 4 comments
Closed

create_tags backtraces when multiples tags are passed #137

iMilnb opened this issue Jun 18, 2015 · 4 comments
Labels
bug This issue is a confirmed bug.

Comments

@iMilnb
Copy link

iMilnb commented Jun 18, 2015

When passing multiple tags to the create_tags method, I get the following backtrace:

  File "boto/ec2.py", line 160, in create
    'Customer': instance['customer']
  File "/usr/home/imil/aws/awscli/lib/python2.7/site-packages/boto3/resources/fa
ctory.py", line 340, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/home/imil/aws/awscli/lib/python2.7/site-packages/boto3/resources/ac
tion.py", line 81, in __call__
    return self._response_handler(parent, params, response)
  File "/usr/home/imil/aws/awscli/lib/python2.7/site-packages/boto3/resources/re
sponse.py", line 240, in __call__
    parent, identifiers, response_item))
  File "/usr/home/imil/aws/awscli/lib/python2.7/site-packages/boto3/resources/re
sponse.py", line 284, in handle_response_item
    value = value.pop(0)
IndexError: pop from empty list

When creating a loop where I create the tags one after the other, everything is going smoothly.

For the record, the taglist has this form:

[{
    'Key': 'Name',
    'Value': 'myinstance'
},{
    'Key': 'Customer',
    'Value': 'mycustomer'
}]

I use boto3 0.0.21

@jamesls
Copy link
Member

jamesls commented Jun 23, 2015

Can you share a code snippet that shows the issue? Here's what I tried, which is working for me:

In [1]: import boto3

In [2]: c = boto3.client('ec2', 'us-west-2')

In [3]: c.create_tags(Resources=['i-id'], Tags=[{'Key': 'foo', 'Value': 'bar'}, {'Key': 'foo2', 'Value': 'bar2'}])
Out[3]:
{'ResponseMetadata': {'HTTPStatusCode': 200,
  'RequestId': 'requestid'}}

@jamesls jamesls added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 23, 2015
@iMilnb
Copy link
Author

iMilnb commented Jun 24, 2015

Of course:

    def mktags(self, taglst):
        '''Makes a Filter-friendly tag list

        :param dict taglst: A dict of key / value pairs

        :return: Filter-friendly tag list
        :rtype: dict
        '''
        tags = []
        for t in taglst:
            tags.append({'Key': t, 'Value': taglst[t]})
        return tags

then the main call:

                        tags = {
                            'Name': '{0}_{1}'.format(
                                dname, instance['name']
                            ),
                            'Customer': instance['customer']
                        }
                        ec2.resource.create_tags(
                            Resources = [dev['Ebs']['VolumeId']],
                            Tags = mktags(tags)
                        )

This code works with a single {'Key': 'foo', 'Value': 'bar'} item

Update

When using ec2.client.create_tags, I have the intended behavior, this bug concerns the resource way of doing things.

@jamesls jamesls removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 24, 2015
@kyleknap
Copy link
Contributor

I can confirm the issue. It looks like we are not handling the case where multiple resources can be returned by an action.

@jamesls
Copy link
Member

jamesls commented Jul 28, 2015

Fixed via #160

@jamesls jamesls closed this as completed Jul 28, 2015
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

3 participants