ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #129: ARIA-213 Sporadic tests failures over...
Date Thu, 11 May 2017 13:26:04 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/129#discussion_r115978355
  
    --- Diff: aria/storage/instrumentation.py ---
    @@ -53,30 +59,76 @@ def track_changes(instrumented=None):
         :param instrumented: A dict from model columns to their python native type
         :return: The instrumentation context
         """
    -    return _Instrumentation(instrumented or _INSTRUMENTED)
    +    return _Instrumentation(ctx, instrumented or _INSTRUMENTED)
     
     
     class _Instrumentation(object):
     
    -    def __init__(self, instrumented):
    +    def __init__(self, ctx, instrumented):
             self.tracked_changes = {}
    +        self.new_instances = {}
             self.listeners = []
    +        self._new_modeled_instances = []
    +        self._ctx = ctx
             self._track_changes(instrumented)
    +        self._new_instance_index = 0
    +
    +    @property
    +    def _new_instance_id(self):
    +        self._new_instance_index += 1
    +        return '{prefix}_{index}'.format(prefix=_NEW_INSTANCE, index=self._new_instance_index
- 1)
    +
    +    def expunge_session(self):
    +        for new_instance in self._new_modeled_instances:
    +            self._get_session_from_ctx(new_instance.__tablename__).expunge(new_instance)
    +
    +    def _get_session_from_ctx(self, tablename):
    +        mapi = getattr(self._ctx.model, tablename, None)
    +        if mapi:
    +            return mapi._session
    +        raise StorageError("Could not retrieve session for {0}".format(tablename))
     
         def _track_changes(self, instrumented):
    -        instrumented_classes = {}
    -        for instrumented_attribute, attribute_type in instrumented.items():
    +        instrumented_attribute_classes = {}
    +        for instrumented_attribute, attribute_type in instrumented.get('modified', {}).items():
                 self._register_set_attribute_listener(
                     instrumented_attribute=instrumented_attribute,
                     attribute_type=attribute_type)
                 instrumented_class = instrumented_attribute.parent.entity
    -            instrumented_class_attributes = instrumented_classes.setdefault(instrumented_class,
{})
    +            instrumented_class_attributes = instrumented_attribute_classes.setdefault(
    +                instrumented_class, {})
                 instrumented_class_attributes[instrumented_attribute.key] = attribute_type
    -        for instrumented_class, instrumented_attributes in instrumented_classes.items():
    -            self._register_instance_listeners(
    +        for instrumented_class, instrumented_attributes in instrumented_attribute_classes.items():
    +            self._register_instance_attribute_listeners(
                     instrumented_class=instrumented_class,
                     instrumented_attributes=instrumented_attributes)
     
    +        # instrument creation of new instances
    +        for instrumented_class in instrumented.get('new', {}):
    +            self._register_instance_listener(instrumented_class)
    +
    +    def _register_instance_listener(self, instrumented_class):
    +        if self._ctx is None:
    +            if instrumented_class:
    --- End diff --
    
    remove


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message