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

Skip stringify if json #355

Merged
merged 21 commits into from
May 10, 2022
Merged

Skip stringify if json #355

merged 21 commits into from
May 10, 2022

Conversation

barrachri
Copy link
Contributor

Fixes #354

Copy link
Contributor

@Linkid Linkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I let you some comments.

auditlog/diff.py Show resolved Hide resolved
auditlog/diff.py Show resolved Hide resolved
@barrachri
Copy link
Contributor Author

Hi @Linkid, can you give the PR another check? Thanks!

@barrachri barrachri requested a review from Linkid April 5, 2022 23:29
Linkid
Linkid previously requested changes May 1, 2022
Copy link
Contributor

@Linkid Linkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry about that, but with the PR #370, django-jsonfield-backport is removed. Then, you can use this line instead:
from django.db.models import JSONField

@alexsavio
Copy link

Sounds good to me. Thanks for the review @Linkid. When are you planning to make a release, though? Thanks a lot!

auditlog/diff.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 8, 2022

Codecov Report

Merging #355 (a7e5a7f) into master (d848c53) will increase coverage by 0.75%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #355      +/-   ##
==========================================
+ Coverage   82.64%   83.39%   +0.75%     
==========================================
  Files          20       20              
  Lines         507      506       -1     
==========================================
+ Hits          419      422       +3     
+ Misses         88       84       -4     
Impacted Files Coverage Δ
auditlog/diff.py 94.11% <100.00%> (+5.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d848c53...a7e5a7f. Read the comment docs.

* master:
  Remove default_app_config configuration
  Fix lint entry in tox.ini
  Drop Django 2.2 support.
  [pre-commit.ci] pre-commit autoupdate
  Fix small typo
  Add mask_fields argument in register (jazzband#310)
  Use pre-commit as lint command
  Add black and isort to .pre-commit-config.yaml
  Replace assertTrue with assertEqual
  enable use of replica database (jazzband#359)
@hramezani
Copy link
Member

Thanks @barrachri for the patch. Please:

  • Rebase your patch
  • Add regression tests to prove the patch.

* master:
  Prepare release of django-auditlog 2.0.0
  Update postgres image version in github action test workflow
  Fix typo in CHANGELOG.md
@barrachri
Copy link
Contributor Author

Thanks @hramezani. Do you think the added tests are enough?

@hramezani
Copy link
Member

Thanks @barrachri for the tests. But I can see your tests are passing without the fix.
You need to add a test that shows the problem which your patch fixes it.

Also, Please add a changelog entry.

@barrachri
Copy link
Contributor Author

Hi @hramezani you can try to run it again, while disabling the elif isinstance(field, JSONField): if branch.

I also added the changelog entry.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
barrachri and others added 2 commits May 9, 2022 18:16
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
auditlog/diff.py Outdated
elif isinstance(field, JSONField):
try:
value = field.to_python(getattr(obj, field.name, None))
except ObjectDoesNotExist:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that covers this except block 🤔 ?

Copy link
Contributor Author

@barrachri barrachri May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no test, in general, that covers the except ObjectDoesNotExist: part of get_field_value.

I am happy to add one though not entirely sure how to replicate that directly with the model (I believe we would need a migration to replicate it with save()).

But I can call model_instance_diff directly, with 2 instances and one has the attribute deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it is a blocker because coverage fails and I can't merge the PR

…into fix-jsonfield

* 'fix-jsonfield' of github.com:barrachri/django-auditlog:
  Update CHANGELOG.md
  Update CHANGELOG.md
hramezani
hramezani previously approved these changes May 9, 2022
Copy link
Member

@hramezani hramezani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @barrachri 👍

@barrachri
Copy link
Contributor Author

barrachri commented May 9, 2022

Thanks @hramezani, I added a new test and refactored the ObjectDoesNotExist try/except.

@hramezani hramezani merged commit a93f539 into jazzband:master May 10, 2022
@barrachri barrachri deleted the fix-jsonfield branch May 10, 2022 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

model_instance_diff and smart_str are not realiable with models.JSONField
4 participants