Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete_record(self, record):
"""
Permanently removes record from table.
"""
try:
self.session.delete(record)
self.session.commit()
except Exception as e:
self.session.rollback()
raise ProgrammingError(e)
finally:
self.session.close()
def delete_record(self, record):
"""
Permanently removes record from table.
"""
try:
self.session.delete(record)
self.session.commit()
except Exception as e:
self.session.rollback()
raise ProgrammingError(e)
finally:
self.session.close()
def run(self):
# Construct process application class.
process_class = self.application_process_class
if not isinstance(process_class, ApplicationWithConcreteInfrastructure):
if self.infrastructure_class:
process_class = process_class.mixin(self.infrastructure_class)
else:
raise ProgrammingError("infrastructure_class is not set")
# Construct process application object.
self.process = process_class(
pipeline_id=self.pipeline_id, setup_table=self.setup_tables
)
# Follow upstream notification logs.
for upstream_name in self.upstream_names:
# Obtain a notification log object (local or remote) for the upstream process.
if upstream_name == self.process.name:
# Upstream is this process's application,
# so use own notification log.
notification_log = self.process.notification_log
else:
# For a different application, we need to construct a notification
self: TSystem, infrastructure_class: Type[ApplicationWithConcreteInfrastructure]
) -> TSystem:
"""
Constructs a system object that has an infrastructure class
from a system object constructed without infrastructure class.
Raises ProgrammingError if already have an infrastructure class.
:param infrastructure_class:
:return: System object that has an infrastructure class.
:rtype: System
"""
# Check system doesn't already have an infrastructure class.
if self.infrastructure_class:
raise ProgrammingError("System already has an infrastructure class")
# Clone the system object, and set the infrastructure class.
system = type(self).__new__(type(self))
system.__dict__.update(dict(deepcopy(self.__dict__)))
system.__dict__.update(infrastructure_class=infrastructure_class)
return system
def delete_record(self, record):
assert isinstance(record, self.record_class), type(record)
try:
record.delete()
except InvalidRequest as e:
raise ProgrammingError(e)
def follow(
self, upstream_application_name: str, notification_log: AbstractNotificationLog
) -> None:
if (
upstream_application_name == self.name
and self.apply_policy_to_generated_events
):
raise ProgrammingError(
"Process application not allowed to follow itself because "
"its 'apply_policy_to_generated_events' attribute is True."
)
# Create a reader.
reader = self.notification_log_reader_class(
notification_log,
use_direct_query_if_available=self.use_direct_query_if_available,
)
self.readers[upstream_application_name] = reader
records,
tracking_kwargs=None,
orm_objs_pending_save=None,
orm_objs_pending_delete=None,
):
all_params = []
statement = None
if records:
# Prepare to insert event and notification records.
statement = self.insert_values
if self.notification_id_name:
all_ids = set((getattr(r, self.notification_id_name) for r in records))
if None in all_ids:
if len(all_ids) > 1:
# Either all or zero records must have IDs.
raise ProgrammingError("Only some records have IDs")
elif self.contiguous_record_ids:
# Do an "insert select max" from existing.
statement = self.insert_select_max
elif hasattr(self.record_class, "application_name"):
# Can't allow auto-incrementing ID if table has field
# application_name. We need values and don't have them.
raise ProgrammingError("record ID not set when required")
for record in records:
# Params for stored item itself (e.g. event).
params = {name: getattr(record, name) for name in self.field_names}
# Params for application partition (bounded context).
if hasattr(self.record_class, "application_name"):
AttributeChanged event.
"""
if isfunction(getter):
def setter(self, value):
assert isinstance(self, EventSourcedEntity), type(self)
name = '_' + getter.__name__
self._change_attribute(name=name, value=value)
def new_getter(self):
assert isinstance(self, EventSourcedEntity), type(self)
name = '_' + getter.__name__
return getattr(self, name)
return property(fget=new_getter, fset=setter)
else:
raise ProgrammingError("Expected a function, got: {}".format(repr(getter)))
if inbox_id not in self.inboxes:
self.inboxes[inbox_id] = self.manager.Queue()
for upstream_class_name in upstream_names:
outbox_id = (pipeline_id, upstream_class_name.lower())
if outbox_id not in self.outboxes:
self.outboxes[outbox_id] = PromptOutbox()
if inbox_id not in self.outboxes[outbox_id].downstream_inboxes:
self.outboxes[outbox_id].downstream_inboxes[
inbox_id
] = self.inboxes[inbox_id]
# Check we have the infrastructure classes we need.
for process_class in self.system.process_classes:
if not isinstance(process_class, ApplicationWithConcreteInfrastructure):
if not self.infrastructure_class:
raise ProgrammingError("infrastructure_class is not set")
elif not issubclass(
self.infrastructure_class, ApplicationWithConcreteInfrastructure
):
raise ProgrammingError(
"infrastructure_class is not a subclass of {}".format(
ApplicationWithConcreteInfrastructure
)
)
# Subscribe to broadcast prompts published by a process
# application in the parent operating system process.
subscribe(handler=self.broadcast_prompt, predicate=self.is_prompt)
# Start operating system process.
for pipeline_id in self.pipeline_ids:
for process_name, upstream_names in self.system.followings.items():
"""
if isfunction(getter):
@no_type_check
def setter(self, value):
name = "_" + getter.__name__
self.__change_attribute__(name=name, value=value)
@no_type_check
def new_getter(self):
name = "_" + getter.__name__
return getattr(self, name, None)
return property(fget=new_getter, fset=setter, doc=getter.__doc__)
else:
raise ProgrammingError("Expected a function, got: {}".format(repr(getter)))