Skip to content
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

refactor logentry config save hook #988

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions ephios/modellogging/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
import itertools
import threading
from typing import Dict
Expand All @@ -16,8 +15,6 @@


class BaseLogConfig:
log_entry_context_manager = contextlib.nullcontext

def initial_log_recorders(self, instance):
"""
Initial log recorders are always added after model __init__.
Expand Down Expand Up @@ -45,6 +42,13 @@ def object_to_attach_logentries_to(self, instance):
"""
return type(instance), instance.pk

def save_logentry(self, logentry: LogEntry):
"""
Save the logentry. Overwrite this method to process the logentry
bevore saving.
"""
logentry.save()


class ModelFieldsLogConfig(BaseLogConfig):
def __init__(self, unlogged_fields=None, attach_to_func=None, initial_recorders_func=None):
Expand Down Expand Up @@ -156,8 +160,7 @@ def update_log(instance, action_type: InstanceActionType):
data=log_data,
)

with config.log_entry_context_manager():
logentry.save()
config.save_logentry(logentry)
instance._current_logentry = logentry


Expand Down