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

Move name collision logic to the model #67

Merged
merged 4 commits into from Feb 27, 2015
Merged

Conversation

danielgtaylor
Copy link
Member

This change moves and formalizes the name collision logic from the factory
to the resource model. The following has changed:

  • Documentation now better matches the factory output.
  • Collision renaming order is formalized in one place
    • Order: reserved names (meta), load action, identifiers, actions,
      subresources, references, collections, and then attributes.
  • Renaming resource model attributes/methods now happens at model loading
    time rather than class creation time.

The way this works is by creating a mapping of (type, name) tuples to
the renamed value, if it exists. Typically this mapping will be very
sparse and it's fast to create / access. In practice we currently only
have one or two names that collide across all the resource models.

Tests have been updated, some of which needed to define proper Botocore
shapes as the code now looks more closely at those at model load time.

cc @kyleknap @jamesls

This change moves and formalizes the name collision logic from the factory
to the resource model. The following has changed:

* Documentation now better matches the factory output.
* Collision renaming order is formalized in one place
  * Order: reserved names (meta), load action, identifiers, actions,
    subresources, references, collections, and then attributes.
* Renaming resource model attributes/methods now happens at model loading
  time rather than class creation time.

The way this works is by creating a mapping of (type, name) tuples to
the renamed value, if it exists. Typically this mapping will be very
sparse and it's fast to create / access. In practice we currently only
have one or two names that collide across all the resource models.

Tests have been updated, some of which needed to define proper Botocore
shapes as the code now looks more closely at those at model load time.
@@ -182,7 +182,7 @@ def test_resource_references(self):
self.assertEqual(len(model.references), 1)

ref = model.references[0]
self.assertEqual(ref.name, 'Frob')
self.assertEqual(ref.name, 'frob')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a bug. This is a reference, and as such should have a snake-cased name.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1e05404 on model-collision into * on develop*.

@danielgtaylor danielgtaylor added the enhancement This issue requests an improvement to a current feature. label Feb 23, 2015
@danielgtaylor danielgtaylor self-assigned this Feb 23, 2015
'type': 'structure',
'members': {}
})
shape.members['ETag'] = Shape('ETag', {'type': 'string'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relying on an implementation detail that is subject to change. members is actually a property (a cached property) that happens to create a mutable attr the first time it's retrieved.

Alternatives:

  • Pass in a ShapeResolver with a shape_map.
  • Use the botocore.model.DenormalizedStructureBuilder.

@jamesls
Copy link
Member

jamesls commented Feb 23, 2015

As someone who hasn't looked at this code in a while, I'm probably missing something, but where are the tests for this feature? Given your description, particularly the second point:

Order: reserved names (meta), load action, identifiers, actions, subresources, references, collections, and then attributes.

I was looking for a test of exactly like this. A resource that had one or more of those, and we verify they get renamed as X, Y, Z.

ResourceModel has two new methods added, but I don't see any explicit tests for this.

This fixes a few issues that cropped up during testing and makes the
handling of renamed attributes safer with respect to autoloaded
resource properties.
@danielgtaylor
Copy link
Member Author

@jamesls @kyleknap please have another look. I've added more tests and fixed a couple of issues. Coverage is the same, but now we are explicitly testing the order of renaming and using the DenormalizedStructureBuilder from Botocore.

@@ -201,44 +191,8 @@ def _load_waiters(self, attrs, model):
"""
for waiter in model.waiters:
snake_cased = xform_name(waiter.resource_waiter_name)
snake_cased = self._check_allowed_name(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see where waiters get checked in the new collision logic.

@kyleknap
Copy link
Member

Looks good. The only thing I did not see was the collision handling for waiters. I talked to you about adding it, even though the chance of collisions for waiter_actions is very small especially since wait_until_ prepends all waiter actions, just to be safe and consistent with the rest of the features in boto3. Once you add it, 🚢.

@danielgtaylor
Copy link
Member Author

@kyleknap please take another look. I've added waiters to the renaming logic, removed the resource_waiter_name attribute as the name is now representative of the resource waiter name, and have cleaned up the factory a bit because the xform_name operations now happen in the model instead. Docs are also up to date.

At this point the model does two things: it loads the JSON data and surfaces it in a Python-friendly way (snake-cased names, and handles renaming so there are no duplicates). Both the factory and docs are a bit simpler now (though I didn't mess much with docs because that will get its own overhaul shortly).

@kyleknap
Copy link
Member

Thanks! 🚢

@jamesls
Copy link
Member

jamesls commented Feb 27, 2015

:shipit:

@danielgtaylor danielgtaylor merged commit 67876fc into develop Feb 27, 2015
@danielgtaylor danielgtaylor deleted the model-collision branch February 27, 2015 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue requests an improvement to a current feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants