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

remove_tag() always deletes tag from internal dictionnary even when "value" does not match #2414

Open
wibou7 opened this Issue Jul 16, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@wibou7

wibou7 commented Jul 16, 2014

This might be a problem with the documentation OR the implementation.
The documentation of remove_tag states:
"An optional value that can be stored with the tag.
If a value is provided, it must match the value
currently stored in EC2. If not, the tag will not
be removed. If a value of None is provided, all
tags with the specified name will be deleted."

However, the code is as follow:
boto/ec2/ec2object.py (line 126)

        if value is not None:
            tags = {key : value}
        else:
            tags = [key]
        status = self.connection.delete_tags(
            [self.id],
            tags,
            dry_run=dry_run
        )
        if key in self.tags:
            del self.tags[key]

AWS will not delete the tag if the value does not match but boto never perform this verification. So remove_tag() will ALWAYS delete the tag from the internal dictionary, but it might still exists on the "real" AWS object.
This behavior is very confusing to the end users because they might think their tag got deleted since they are no longer in the internal dict but in reality AWS would still have them.
Mitigation for the end users is to reload the object each time a remove_tag() is performed, but that implies a deep understanding of the internal of the library.

Example
  1. Add a tag to any e2 object (e.g. ec2.Instance or Subnet) with a certain value.
  2. Call the remove_tag() on that object while specifying a DIFFERENT VALUE than the one set. According to documentation, the tag should NOT be removed.
  3. Look at the .tags of the object : the tag will have been removed, although it still exists on the "real" AWS object.

Code sample:

# Assuming object is an existing Instance/Subnet/Vpc/..
object.add_tag("TEST", "abcdef")     # Note that the value is abcdef
object("Before:" + str(object.tags))
object.remove_tag("TEST", "123456")  # Value is wrong, WONT be deleted from AWS
print("After:" + str(object.tags))   # It was deleted?!?
@danielgtaylor

This comment has been minimized.

Show comment
Hide comment
@danielgtaylor

danielgtaylor Jul 29, 2014

Member

This definitely looks like a bug and not a documentation problem.

Member

danielgtaylor commented Jul 29, 2014

This definitely looks like a bug and not a documentation problem.

danielgtaylor added a commit that referenced this issue Oct 7, 2014

Merge pull request #2610 from EaterOA/develop
Added TaggedEC2Object.remove_tags. Fixes #2269, #2414, #2610.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment