Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C6508200C63 for ; Thu, 11 May 2017 15:26:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C4D8F160BCF; Thu, 11 May 2017 13:26:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 16E8B160BCE for ; Thu, 11 May 2017 15:26:09 +0200 (CEST) Received: (qmail 20919 invoked by uid 500); 11 May 2017 13:26:09 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 20828 invoked by uid 99); 11 May 2017 13:26:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 May 2017 13:26:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 92987C322C for ; Thu, 11 May 2017 13:26:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.021 X-Spam-Level: X-Spam-Status: No, score=-4.021 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 3rMxn_PXULWR for ; Thu, 11 May 2017 13:26:06 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 5AB815FC43 for ; Thu, 11 May 2017 13:26:05 +0000 (UTC) Received: (qmail 20336 invoked by uid 99); 11 May 2017 13:26:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 May 2017 13:26:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5C5B2DFFB2; Thu, 11 May 2017 13:26:04 +0000 (UTC) From: mxmrlv To: dev@ariatosca.incubator.apache.org Reply-To: dev@ariatosca.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #129: ARIA-213 Sporadic tests failures over... Content-Type: text/plain Message-Id: <20170511132604.5C5B2DFFB2@git1-us-west.apache.org> Date: Thu, 11 May 2017 13:26:04 +0000 (UTC) archived-at: Thu, 11 May 2017 13:26:10 -0000 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. ---