Add `StreamField.get_db_prep_value()` to delegate serialisation of `JSONField` lookup values ()

Fixes 
pull/9698/head
Sage Abdullah 2022-11-17 15:06:15 +00:00 zatwierdzone przez Matt Westcott
rodzic 682ed3b21f
commit 573107a3b6
3 zmienionych plików z 12 dodań i 0 usunięć
docs/releases
wagtail

Wyświetl plik

@ -34,6 +34,7 @@ Changelog
* Fix: Move DateField, DateTimeField, TimeField comment buttons to be right next to the fields (Theresa Okoro)
* Fix: Support text resizing in workflow steps cards (Ivy Jeptoo)
* Fix: Ignore images added via fixtures when using `WAGTAILIMAGES_FEATURE_DETECTION_ENABLED` to avoid errors for images that do not exist (Aman Pandey)
* Fix: Restore ability to perform JSONField query operations against StreamField when running against the Django 4.2 development branch (Sage Abdullah)
* Docs: Add custom permissions section to permissions documentation page (Dan Hayden)
* Docs: Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare)
* Docs: Officially recommend `fnm` over `nvm` in development documentation (LB (Ben) Johnston)

Wyświetl plik

@ -46,6 +46,7 @@ depth: 1
* Move DateField, DateTimeField, TimeField comment buttons to be right next to the fields (Theresa Okoro)
* Support text resizing in workflow steps cards (Ivy Jeptoo)
* Ignore images added via fixtures when using `WAGTAILIMAGES_FEATURE_DETECTION_ENABLED` to avoid errors for images that do not exist (Aman Pandey)
* Restore ability to perform JSONField query operations against StreamField when running against the Django 4.2 development branch (Sage Abdullah)
### Documentation

Wyświetl plik

@ -212,8 +212,18 @@ class StreamField(models.Field):
)
else:
# When querying with JSONField features, the rhs might not be a StreamValue.
# Note: when Django 4.2 is the minimum supported version, this can be removed
# as the serialisation is handled in get_db_prep_value instead.
return self.json_field.get_prep_value(value)
def get_db_prep_value(self, value, connection, prepared=False):
if self.use_json_field and not isinstance(value, StreamValue):
# When querying with JSONField features, the rhs might not be a StreamValue.
# As of Django 4.2, JSONField value serialisation is handled in
# get_db_prep_value instead of get_prep_value.
return self.json_field.get_db_prep_value(value, connection, prepared)
return super().get_db_prep_value(value, connection, prepared)
def from_db_value(self, value, expression, connection):
if self.use_json_field and isinstance(expression, KeyTransform):
# This could happen when using JSONField key transforms,