def resolve(self, id): class_path, oid = id.split('-', 1) oid, lang = oid.split(":", 1) domain_class = resolve.resolve(class_path) session = Session() value_key = container.valueKey(oid) return session.query(domain_class).get(value_key)
def getValueKey(self, context): """iterate through the parents until you get a valueKey """ if context.__parent__ is None: return None else: try: value_key = valueKey(context.__parent__.__name__)[0] except: value_key = self.getValueKey(context.__parent__) return value_key
def resolve(self, id): class_path, oid = id.split('-', 1) domain_class = resolve.resolve(class_path) session = Session() value_key = container.valueKey(oid) obj = session.query(domain_class).get(value_key) if not obj: session.commit() obj = session.query(domain_class).get(value_key) return obj
def resolve(self, id): class_path, oid = id.split('-', 1) domain_class = resolve.resolve(class_path) session = Session() value_key = container.valueKey(oid) if "None" not in value_key: obj = session.query(domain_class).get(value_key) else: obj = None return obj
def serialization_notifications_callback(channel, method, properties, body): """Publish an object to XML on receiving AMQP message """ # set up thread local cache thread_locals.serialize_cache = {} obj_data = simplejson.loads(body) obj_type = obj_data.get("obj_type") domain_model = getattr(domain, obj_type, None) if domain_model: obj_key = valueKey(obj_data.get("obj_key")) session = Session() obj = session.query(domain_model).get(obj_key) if obj: try: publish_to_xml(obj) except Exception, e: ex_type, ex, tb = sys.exc_info() log.warn("Error while publish_to_xml : %r", traceback.format_tb(tb)) log.warn("Error info type: %s, obj_key: %s, obj: %s", obj_type, obj_key, obj) # requeue, usually fails becuase of an object introspection timeout # so we simply retry channel.basic_reject(delivery_tag=method.delivery_tag, requeue=True ) notify_serialization_failure(SERIALIZE_FAILURE_TEMPLATE, obj=obj, message=obj_data, error=e) else: # no exceptions so acknowledge the message channel.basic_ack(delivery_tag=method.delivery_tag) else: log.error("Could not query object of type %s with key %s. " "Check database records - Rejecting message.", domain_model, obj_key ) # reject the message channel.basic_reject(delivery_tag=method.delivery_tag, requeue=False ) session.close()