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

Avoid DB savepoints if no audit is going to be created #232

Merged
merged 1 commit into from
Sep 4, 2022
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
27 changes: 14 additions & 13 deletions easyaudit/signals/model_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs):
return

try:
if not should_audit(instance):
return False

with transaction.atomic(using=using):
if not should_audit(instance):
return False
try:
object_json_repr = serializers.serialize("json", [instance])
except Exception:
Expand Down Expand Up @@ -132,9 +133,10 @@ def post_save(sender, instance, created, raw, using, update_fields, **kwargs):
return

try:
if not should_audit(instance):
return False

with transaction.atomic(using=using):
if not should_audit(instance):
return False
object_json_repr = serializers.serialize("json", [instance])

# created or updated?
Expand Down Expand Up @@ -211,13 +213,12 @@ def _m2m_rev_field_name(model1, model2):
def m2m_changed(sender, instance, action, reverse, model, pk_set, using, **kwargs):
"""https://docs.djangoproject.com/es/1.10/ref/signals/#m2m-changed"""
try:
with transaction.atomic(using=using):
if not should_audit(instance):
return False

if action not in ("post_add", "post_remove", "post_clear"):
return False
if not should_audit(instance):
return False
if action not in ("post_add", "post_remove", "post_clear"):
return False

with transaction.atomic(using=using):
object_json_repr = serializers.serialize("json", [instance])

if reverse:
Expand Down Expand Up @@ -301,10 +302,10 @@ def crud_flow():
def post_delete(sender, instance, using, **kwargs):
"""https://docs.djangoproject.com/es/1.10/ref/signals/#post-delete"""
try:
with transaction.atomic(using=using):
if not should_audit(instance):
return False
if not should_audit(instance):
return False

with transaction.atomic(using=using):
object_json_repr = serializers.serialize("json", [instance])

# user
Expand Down