-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate clock_tick context manager #39
base: master
Are you sure you want to change the base?
Changes from all commits
5ed28fb
f2c2229
6512d60
3df510d
9afe85b
d7e52ad
c97443e
de145e4
e06df10
44eb508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
from temporal_sqlalchemy import nine, util | ||
from temporal_sqlalchemy.bases import ( | ||
T_PROPS, | ||
ClockState, | ||
ActivityState, | ||
Clocked, | ||
TemporalOption, | ||
TemporalActivityMixin, | ||
|
@@ -78,6 +80,10 @@ def temporal_map(*track, mapper: orm.Mapper, activity_class=None, schema=None): | |
backref_name = '%s_clock' % entity_table.name | ||
clock_properties['activity'] = \ | ||
orm.relationship(lambda: activity_class, backref=backref_name) | ||
cls.activity = ActivityState() | ||
event.listen(cls, 'expire', ActivityState.reset_activity) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NicoleZuckerman this the |
||
for prop in tracked_props: | ||
event.listen(prop, 'set', ActivityState.activity_required) | ||
|
||
clock_model = build_clock_class(cls.__name__, | ||
entity_table.metadata, | ||
|
@@ -94,24 +100,19 @@ def temporal_map(*track, mapper: orm.Mapper, activity_class=None, schema=None): | |
clock_model=clock_model, | ||
activity_cls=activity_class | ||
) | ||
|
||
cls.current_clock = ClockState() | ||
event.listen(cls, 'expire', ClockState.reset_tick) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NicoleZuckerman this is the expire for the |
||
event.listen(cls, 'init', init_clock) | ||
|
||
|
||
def init_clock(obj: Clocked, args, kwargs): | ||
kwargs.setdefault('vclock', 1) | ||
initial_tick = obj.temporal_options.clock_model( | ||
tick=kwargs['vclock'], | ||
entity=obj, | ||
) | ||
obj.current_clock = obj.temporal_options.clock_model(tick=kwargs['vclock']) | ||
|
||
if obj.temporal_options.activity_cls and 'activity' not in kwargs: | ||
raise ValueError( | ||
"%r missing keyword argument: activity" % obj.__class__) | ||
|
||
if 'activity' in kwargs: | ||
initial_tick.activity = kwargs.pop('activity') | ||
|
||
materialize_defaults(obj, kwargs) | ||
|
||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note here about using
getattr
without a default argument.However, be warned: attributes starting with double underscores may not behave as you expect. Python has a concept of "private variables" that may result in an
AttributeError
getting thrown.From the docs:
Because it's required to occur inside the class definition I think this will be okay, but I thought I'd point it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think in this case it's okay, but it's a good call out