From 6f7a758a48aa758bebdf49465cfeaffea3762df7 Mon Sep 17 00:00:00 2001 From: Abdullah Alaqeel Date: Wed, 20 Sep 2023 13:23:45 +0300 Subject: [PATCH] fix: don't set the correlation_id if the `AUDITLOG_CID_GETTER` is `None` (#565) --- CHANGELOG.md | 15 +++++++++++++-- auditlog/cid.py | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8914baa..39bb756 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,22 @@ ## Next Release +#### Improvements +- Python: Confirm Python 3.12 support ([#572](https://github.com/jazzband/django-auditlog/pull/572)) + +## 3.0.0-beta.2 (2023-10-05) + +#### Breaking Changes +- feat: stop deleting old log entries when a model with the same pk is created (i.e. the pk value is reused) ([#559](https://github.com/jazzband/django-auditlog/pull/559)) + +#### Fixes +* fix: don't set the correlation_id if the `AUDITLOG_CID_GETTER` is `None` ([#565](https://github.com/jazzband/django-auditlog/pull/565)) + +## 3.0.0-beta.1 + #### Breaking Changes -- Python: Confirm Python 3.12 support ([#572](https://github.com/jazzband/django-auditlog/pull/572)) - feat: Change `LogEntry.change` field type to `JSONField` rather than `TextField`. This change include a migration that may take time to run depending on the number of records on your `LogEntry` table ([#407](https://github.com/jazzband/django-auditlog/pull/407))([#495](https://github.com/jazzband/django-auditlog/pull/495)) -- feat: stop deleting old log entries when a model with the same pk is created (i.e. the pk value is reused) ([#559](https://github.com/jazzband/django-auditlog/pull/559)) - feat: Set `AuditlogHistoryField.delete_related` to `False` by default. This is different from the default configuration of Django's `GenericRelation`, but we should not erase the audit log of objects on deletion by default. ([#557](https://github.com/jazzband/django-auditlog/pull/557)) - Python: Drop support for Python 3.7 ([#546](https://github.com/jazzband/django-auditlog/pull/546)) diff --git a/auditlog/cid.py b/auditlog/cid.py index e530869..8d2aa9f 100644 --- a/auditlog/cid.py +++ b/auditlog/cid.py @@ -13,11 +13,16 @@ def set_cid(request: Optional[HttpRequest] = None) -> None: A function to read the cid from a request. If the header is not in the request, then we set it to `None`. - Note: we look for the header in `request.headers` and `request.META`. + Note: we look for the value of `AUDITLOG_CID_HEADER` in `request.headers` and in `request.META`. + + This function doesn't do anything if the user is supplying their own `AUDITLOG_CID_GETTER`. :param request: The request to get the cid from. :return: None """ + if settings.AUDITLOG_CID_GETTER: + return + cid = None header = settings.AUDITLOG_CID_HEADER