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
Drop jsonfield package for django's native JSONField #2824
Conversation
I don't think you planned to include the Edit: Thank you for picking that up! |
Codecov Report
@@ Coverage Diff @@
## master #2824 +/- ##
=======================================
Coverage 89.41% 89.41%
=======================================
Files 207 207
Lines 10486 10486
Branches 1011 1011
=======================================
Hits 9376 9376
Misses 796 796
Partials 314 314
Continue to review full report at Codecov.
|
f07c428
to
9d4ecda
Compare
Looks great, just one thing, we've just merged #2811, which introduced another Also, I think that |
|
I think we might just drop it from requirements.in then, as it’s not required directly by Saleor |
Alright, on it. |
9d4ecda
to
e774de4
Compare
saleor/order/models.py
Outdated
blank=True, default={}, | ||
dump_kwargs={'cls': CustomJsonEncoder, 'separators': (',', ':')}) | ||
blank=True, default=dict, | ||
encoder=CustomJsonEncoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will all fit on line 331.
Also, I suppose we need to generate a new migration to reflect the encoder
change on the parameters
field, don't we?
e774de4
to
5a7c819
Compare
Review has been factored in. Please take a look again. |
Looks good to me, thanks for contributing to Saleor! Will merge the PR tomorrow. |
Happy to help! |
There's a problem when migrating from the old instance with JSON data created (eg. checkout from the master, generate data via
The ugly quick fix I've tried
But have not investigated what are the differences between |
Alright. I will look into this. |
I used django's interactive shell and tried the following code: from saleor.menu.models import Menu
val = Menu.objects.first().json_content
print(val) This is the result I got running [{"url": "/en/products/category/apparel-1/", "name": "Apparel", "translations": {}, "child_items": []}, {"url": "/en/products/category/accessories-2/", "name": "Accessories", "translations": {}, "child_items": []}, {"url": "/en/products/category/groceries-3/", "name": "Groceries", "translations": {}, "child_items": [{"url": "/en/products/category/coffees-4/", "name": "Coffees", "translations": {}, "child_items": []}, {"url": "/en/products/category/candies-5/", "name": "Candies", "translations": {}, "child_items": []}]}, {"url": "/en/products/category/books-6/", "name": "Books", "translations": {}, "child_items": []}] Running
Still unsure, still investigating. Edit: please can you share with me where the |
Steps to reproduce for me:
Is that how you've reproduced it? |
@the-bionic |
I have noticed some differences in how they both work:
Here is a snippet from class JSONField(JSONFieldBase, models.TextField):
"""JSONField is a generic textfield that serializes/deserializes JSON objects"""
form_class = JSONFormField
def dumps_for_display(self, value):
kwargs = {"indent": 2}
kwargs.update(self.dump_kwargs)
return json.dumps(value, ensure_ascii=False, **kwargs) |
@Pacu2 Dog.objects.create(name='Rufus', data={
'breed': 'labrador',
'owner': {
'name': 'Bob',
'other_pets': [{
'name': 'Fishy',
}],
},
})
Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': None})
Dog.objects.filter(data__breed='collie')
<QuerySet [<Dog: Meg>]> This part of the codebase will be touched to return a dictionary: I also don't know how many more lines like there are. |
@the-bionic I agree, we could rework this to work with dictionaries instead. |
I am worried about something though, for the JSONFields to be changed from We should take a new approach to it, like the one in this stackoverflow answer, then we migrate the data from string-base to dictionaries. |
07d1436
to
24d4bdf
Compare
Updated PR. Should work as expected now. |
def populate_data(apps, schema_editor): | ||
Menu = apps.get_model('menu', 'Menu') | ||
for menu in Menu.objects.all(): | ||
if isinstance(menu.json_content, str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@the-bionic I'm still having an issue with the Menu
being a str.
I wonder if we can just change from if
to while
in here, wouldn't that solve the problem?
Is it possible that we've stored a json_content
as a str
, inside of text-based JSONField? Wouldn't that make it the double nested string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pacu2 Yes that did it. I did not realize it was a deeply nested string. The logic for resolving the nested string, though, is a little bit more than changing the if
condition to a while
loop, since we transferring the content of a text-based JSONField to a jsonb-based JSONField, before dropping the text-based one.
PR updated again. Thanks.
24d4bdf
to
b486975
Compare
Works like a charm. Thank you very much for taking care of this issue. The scope was bigger than planned, but you've handled it like a boss. Congrats on your first contribution to Saleor! |
I'm humbled. Thanks for being patient with me. :) |
I want to merge this change because...
resolve #2802
I could not completely remove the package from requirements.txt because django-prices depends on it.
Screenshots
Pull Request Checklist