-
Notifications
You must be signed in to change notification settings - Fork 413
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 serialized object field #412
Add serialized object field #412
Conversation
Codecov Report
@@ Coverage Diff @@
## master #412 +/- ##
==========================================
+ Coverage 91.79% 92.24% +0.44%
==========================================
Files 23 24 +1
Lines 646 709 +63
==========================================
+ Hits 593 654 +61
- Misses 53 55 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This PR contains a migration. If the wonderful maintainers of django-auditlog would help my team out tremendously by adding this to their project, we would need to be mindful of any other PR's with migrations that might also make it into the release. For example, #407 also contains a migration and we'd need to coordinate that with this one so that they don't have shared dependencies. I'm also aware that I'd need to add something to the change log here. Let me know what you all think of this PR and if you're feeling positive about it, I'll write something up. |
A field was added to the LogEntry model to store a serialized dictionary of key value pairs representing the state of the object after the create, update, or delete action. This field is populated optionally using an `auditlog.regester` kwarg.
e0641e5
to
d0ec818
Compare
Given some of the feedback here, I've made a few adjustments. I'm still optimistic that you all may still be favorable to including the I can understand if the contents of the Please let me know if you all have any other concerns that could be mitigated. |
Thanks @sum-rock for the update. I will take a look whenever I have time. |
To me, the change has two parts
I think we can remove the
I would like to know what do you think @sum-rock and @rposborne? |
Absolutely. I wanted to decouple these things as much as possible while keeping them in the same PR. (In hind sight, maybe that wasn't the correct approach).
I generally agree with this point. I wasn't going to add anything for that PR initially but decided to attempt to incorporate something to both show the value of the
I'm not sure about needing a separate method for the different query filters because we are looking for the state of an object or field at a given time and that's accomplished with Overall, I think I'm in alignment with your points here @hramezani. You'd like auditlog to focus on recording actions and changes rather than on having full featured queries for the retrieval of those records. I think that is completely valid. I'm going to remove the |
Thanks for your understanding @sum-rock |
Test cases were added to assert the serialized data field is functioning as intended and that the registration kwargs are implemented as written.
d0ec818
to
b860d59
Compare
48953c8
to
b860d59
Compare
Why did you add the changes from the other PR here? |
@hramezani I really apologize for that. I had some git madness on my end and unintentionally made that happen. It's fixed now. I was hoping it would be fixed before you'd notice 🙈 . |
Please add documentation into usage after |
A few redundant lines were able to be elimited from the set logic. Statment now takes the set of included fields (or all fields if no included list was found) and removes the fields present in the excluded list.
@alieh-rymasheuski as you left some comments on this PR, It would be great if you check the updates here. |
The `_mask_serialized_fields` method had been receiving a all model field options but only required the `mask_fields` value. The relative import for `mask_str` function was also changed to be an absolute import.
@hramezani, passing this pull request back to you. I don't have objections to merging this pull request. |
Thanks @alieh-rymasheuski for the review. I will take a final look later and will merge it. |
@hramezani Before you guys merge. I'm looking into something that's coming up with implementing this in our system. The issue occurs if datetimes are written as strings on in-memory model fields. Without It may be advisable to add a |
The Django core serializer assumes that the values on object fields are correctly typed to their respective fields. Updates made to an object's in-memory state may not meet this assumption. To prevent this violation, values are typed by calling `to_python` from the field object, the result is set on a copy of the instance and the copy is sent to the serializer. For example, a datetime parsed as a string and set on a `models.DateTimeField()` field is normally written to the database as a string and set to a python datetime object when read on the model. Therefore, no error is raised on save when a datetime field contains a string formatted datetime. The serializer, however, expects a datetime object and will attempt to call `isoformat()` to convert the datetime object to a string which then raises an attribute error.
@hramezani @alieh-rymasheuski I was running our testing suite with these changes this morning and noticed a few unexpected errors. After fully untangling the stacktrace this afternoon I believe I've found the issue and put together a correction. I do think it is best to put the correction in this PR rather than relying on developers to correct in their own code. Avoiding any disruption, even if users need to opt into this new feature, is in everyone's interest. Take a look at what I've written and let me know your thoughts. I've tried to include an explanation in the doc string and commit message so I'll avoid repeating it here. One thing I might add is that the try/except around the Thanks again for your time and dedication, our entire team is very grateful. |
@hramezani why milestone 2.2? This seems to be a backwards-compatible change so it can be include in a 1.X feature release. UPD: please ignore this message, I forgot that auditlog version was already 2.X. |
@alieh-rymasheuski why |
Removed an unnecessary call to copy the data sent to the mask serialize data method. An in method import was also changed to be absolute rather than relative.
With this strategy, a value is not require to determine if the field should be skipped when performing the ``to_python`` call. This is preferred because there are a few edge cases around creating log entries as a result of a cascade delete. In those cases, there are situations when the system attempts to get a value that has already been deleted.
Added a two line change due to an edge case. This wasn't happening in normal cascade delete circumstances but it showed up in "real world" use cases where there are lots of interdependencies. We're rolling this out into production here within the next few days so feel confident that if there are any other bugs, I'll be on to squash them. |
Thanks @sum-rock for your effort! |
This work creates the basic implementation of the
LogEntry.serialized_object
field. This field tracks the state of an object following a create, update, or delete action. A manager method is also added to retrieve the value of an object's field at a given date.Efforts were taken to make sure this addition is not disruptive to current installations of django-auditlog. Specifically, this is an opt-in feature per model. Users are able to opt in by adding the
serialize_data=True
kwarg to the model registration.This relates to issue 410.