added process_session to sync_hier_attr action so session for processing is separated from shared session

This commit is contained in:
iLLiCiTiT 2019-08-02 14:16:58 +02:00
parent c139c7f3e2
commit 52c4580bdc
3 changed files with 31 additions and 14 deletions

View file

@ -54,10 +54,17 @@ class SyncHierarchicalAttrs(BaseAction):
})
session.commit()
process_session = ftrack_api.Session(
server_url=session.server_url,
api_key=session.api_key,
api_user=session.api_user,
auto_connect_event_hub=True
)
try:
# Collect hierarchical attrs
custom_attributes = {}
all_avalon_attr = session.query(
all_avalon_attr = process_session.query(
'CustomAttributeGroup where name is "avalon"'
).one()
for cust_attr in all_avalon_attr['custom_attribute_configurations']:
@ -93,7 +100,9 @@ class SyncHierarchicalAttrs(BaseAction):
self.db_con.install()
self.db_con.Session['AVALON_PROJECT'] = project_name
for entity in entities:
_entities = self._get_entities(event, process_session)
for entity in _entities:
for key in custom_attributes:
# check if entity has that attribute
if key not in entity['custom_attributes']:

View file

@ -88,10 +88,16 @@ class SyncHierarchicalAttrs(BaseAction):
})
session.commit()
process_session = ftrack_api.Session(
server_url=session.server_url,
api_key=session.api_key,
api_user=session.api_user,
auto_connect_event_hub=True
)
try:
# Collect hierarchical attrs
custom_attributes = {}
all_avalon_attr = session.query(
all_avalon_attr = process_session.query(
'CustomAttributeGroup where name is "avalon"'
).one()
for cust_attr in all_avalon_attr['custom_attribute_configurations']:
@ -127,7 +133,9 @@ class SyncHierarchicalAttrs(BaseAction):
self.db_con.install()
self.db_con.Session['AVALON_PROJECT'] = project_name
for entity in entities:
_entities = self._get_entities(event, process_session)
for entity in _entities:
for key in custom_attributes:
# check if entity has that attribute
if key not in entity['custom_attributes']:

View file

@ -209,21 +209,21 @@ class BaseHandler(object):
event
]
def _get_entities(self, event):
self.session._local_cache.clear()
selection = event['data'].get('selection', [])
def _get_entities(self, event, session=None):
if session is None:
session = self.session
session._local_cache.clear()
selection = event['data'].get('selection') or []
_entities = []
for entity in selection:
_entities.append(
self.session.get(
self._get_entity_type(entity),
entity.get('entityId')
)
)
_entities.append(session.get(
self._get_entity_type(entity, session),
entity.get('entityId')
))
event['data']['entities_object'] = _entities
return _entities
def _get_entity_type(self, entity):
def _get_entity_type(self, entity, session=None):
'''Return translated entity type tht can be used with API.'''
# Get entity type and make sure it is lower cased. Most places except
# the component tab in the Sidebar will use lower case notation.