-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add new Event type stateless #352
Conversation
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.
Improve the migrations and see other comments.
Also, first letter upper case in commit-messages please. Hm, sounds like a candidate for a pre-commit hook!
def update_event_type(apps, schema_editor): | ||
# Change INCIDENT_START events for stateless incidents to STATELESS | ||
Event = apps.get_model('argus_incident', 'Event') | ||
for event in Event.objects.all(): | ||
if event.type == "STA" and event.incident.end_time == None: | ||
event.type="LES" | ||
event.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('argus_incident', '0004_alter_event_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_event_type), | ||
] |
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.
Move this into the previous file (the function and append the RunPython to the end of the operations
list.
Also, add a reversal function (second arg to RunPython).
tests/incident/test_event.py
Outdated
description=f"Incident #{source_incident_id} created for testing", | ||
) | ||
event_stateless = incident.events.filter(type=Event.Type.STATELESS) | ||
self.assertEqual(1, len(event_stateless)) |
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.
event_stateless
is a queryset, so do event_stateless.count()
instead of len()
. This makes postgres do the count, not python.
Oh, and you're working from an outdated master-branch, so there might be merge-shenaningans. |
Instead of first event being INCIDIENT_START, now stateless events use the STATELESS event type. Stateful incididents still get an INCIDENT_START event
009d823
to
d6c404a
Compare
Added reverse function for migration. |
def remove_stateless_event_type(apps, schema_editor): | ||
# undo changes made by add_stateless_event_type | ||
Event = apps.get_model('argus_incident', 'Event') | ||
for event in Event.objects.all(): | ||
if event.type == "LES": | ||
event.type = "STA" | ||
event.save() |
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.
Chef's kiss! Mwah!
I don't think there is, and I think it is three letters because that's the length of "END". The sole purpose of saving a string here instead of a key to a data table is for human convenience, and it isn't that much more expensive to have a much longer string, and not even demand the same length for each. |
Fix for #346
Adds new event type called
STATELESS
. This is used instead ofINCIDENT_START
for the initial event when a stateless incident is created. Stateful incident will still start with aÌNCIDENT_START
event.Adds a small test that checks if a stateless event is created when a new stateless incidents is created.
Adds migration files for adding
STATELESS
type and update old entries such thatINCIDENT_START
events that belong to stateless incidents get switched toSTATELESS
.