-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Replace PageRevision
with generic Revision
model
#8441
Conversation
Manage this branch in SquashTest this branch here: https://laymonagegeneric-revision-ais9h.squash.io |
e362c5d
to
8716230
Compare
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've added some initial updates to the docs. Might need to get a better decision on the page
property, though. Kindly review @kaedroho, thanks!
wagtail/models/__init__.py
Outdated
@cached_property | ||
def page(self): | ||
return self.content_object | ||
|
||
@cached_property | ||
def page_id(self): | ||
return int(self.object_id) |
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.
We should either get rid of this now or add some documentation and deprecation warning and get rid of this later. Or maybe leave this in as a shorthand, but make it undocumented?
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 haven't got a strong opinion on this. @gasman what do you think?
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'd go for the deprecation. It seems like something people are likely to be using in the wild, but that we don't want to keep around indefinitely.
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.
Should this be removed in Wagtail 5.0, or 6.0?
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.
Let's say 5.0, since we don't know at this point how far into the future 5.0 and 6.0 are going to be. (I know this tripped us up with use_json_field
, and we're still figuring things out - but I think we can make it work as long as we hold off on doing the actual removals for version N until version N-1 has been released and bakerydemo is updated accordingly).
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.
Okay, thanks! I've added the deprecation warnings. Let me know if there are any changes needed.
Revision.objects.all().update( | ||
base_content_type=page_type, | ||
content_type_id=Cast( | ||
KeyTextTransform("content_type", models.F("content")), |
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.
It turns out we can't cast jsonb
into integer
directly. We need to extract the value as text using the ->>
operator before casting it. So, instead of doing content__content_type
(which implicitly use the KeyTransform
's ->
operator), we should use KeyTextTransform
, which extracts the value using the ->>
operator.
See:
- https://stackoverflow.com/questions/52457637/postgres-cannot-cast-type-jsonb-to-integer
- https://stackoverflow.com/questions/25809744/cast-from-json-to-int-not-working
- https://stackoverflow.com/questions/24826385/how-to-convert-postgresql-9-4s-jsonb-type-to-float
Note: both transforms work the same way on other database backends, so this isn't an issue.
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.
Nice one!
Sounds like we should manually test this one on SQLite/MySQL to make sure the behaviour is the same
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've confirmed that it works on SQLite.
I haven't tested the migration on MySQL, but the query should work:
https://www.db-fiddle.com/f/gNvMtEFUYh2drgBAKjqiL5/0
Anyway, the distinction is only made for PostgreSQL anyway:
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.
Hey y'all,
When I install the current main
with this PR's commits on bakerydemo, with a fresh SQLite database, and run migrations for the first time, it errors out on 0070 with the following:
django.db.utils.NotSupportedError: Renaming the 'wagtailcore_pagerevision' table while in a transaction is not supported on SQLite < 3.26 because it would break referential integrity. Try adding
atomic = False
to the Migration class.
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.
Thanks for the report, for some reason I did not run into that issue but it seems others have run into it too. We can continue the discussion in #8635.
afa8d86
to
d77d1f0
Compare
Revision.objects.all().update( | ||
base_content_type=page_type, | ||
content_type_id=Cast( | ||
KeyTextTransform("content_type", models.F("content")), |
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.
Nice one!
Sounds like we should manually test this one on SQLite/MySQL to make sure the behaviour is the same
22f7d4a
to
cee3b9a
Compare
d0bcba9
to
bbc9d98
Compare
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.
Really happy with this! Just a couple of documentation nitpicks.
…ecific_content_object property
bbc9d98
to
dc0f41d
Compare
This PR replaces the
PageRevision
model with a more genericRevision
model. Instead of using aForeignKey
directly to thePage
model, we're using aCharField
object_id
and a couple ofForeignKey
s to theContentType
model. We are not using theGenericForeignKey
field due to complexities it adds when handling the default/specific Page models (see also ticket 16055 in Django). However, we try to simulate the same behaviour as theGenericForeignKey
wherever possible.Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Footnotes
Development Testing ↩
Browser and device support ↩
Accessibility Target ↩