mtalexan / VersionOne.SDK.Python

A library for custom Python development against the VersionOne Platform's REST-based API.
BSD 3-Clause "New" or "Revised" License
1 stars 3 forks source link

Memoize broken #24

Closed mtalexan closed 6 years ago

mtalexan commented 6 years ago

The @memoize used in the v1meta.py file on the asset_class() attempts to cache lookups on objects so it doesn't need to re-query for objects. It completely breaks all commits() much of the querying though.

The @memoize applies to all objects of that type that are ever created within the Python instantiation. If a script needs to repeatedly create new v1meta objects to independently query for different items (like Stories), examine them, and possibly perform an update on one or more of the fields, the @memoized decorator is preventing any item after the first from ever being updated.

In a test case, a Story is queried for using a particular field, the title is updated, and it is committed. This is repeated for additional stories where the title field also needs to be updated. With the @memoized, only the first Story being changed takes effect. Without the @memoized, all the Story titles are updated. This seems to be a case where the exact same asset_type_name is being queried from the V1Meta instance, which means the arguments to the asset_class() method are the same. However since the initial query filling the underlying response data is different on the subsequent instances, the previous memoized return values are no longer accurate for the identical method arguments.