kopia lustrzana https://github.com/wagtail/wagtail
Don't update descendant urls if slug not updated
Fixes #735 Previously, if you called Page.save with update_fields and didn't include 'slug', it would still attempt to update URL paths of descendant pages. Wagtail 0.7 introduced a feature where it saves the latest revisions created at date on the Page. This requires a Page.save call which used update_fields. The bug caused update_descendant_paths to be called anyway even though the slug wasn't committed to the database. This caused Issue 735 because publishing a page will both save a revision and save a page causing two hits to update_descendant_paths. Running this method twice caused all descendant pages url_path attributes to get mangled.pull/769/head
rodzic
0067935971
commit
5db1539e0a
|
@ -337,14 +337,17 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
|
|||
# has been set and so we can safely call get_parent
|
||||
self.set_url_path(self.get_parent())
|
||||
else:
|
||||
# see if the slug has changed from the record in the db, in which case we need to
|
||||
# update url_path of self and all descendants
|
||||
old_record = Page.objects.get(id=self.id)
|
||||
if old_record.slug != self.slug:
|
||||
self.set_url_path(self.get_parent())
|
||||
update_descendant_url_paths = True
|
||||
old_url_path = old_record.url_path
|
||||
new_url_path = self.url_path
|
||||
# Check that we are committing the slug to the database
|
||||
# Basically: If update_fields has been specified, and slug is not included, skip this step
|
||||
if not ('update_fields' in kwargs and 'slug' not in kwargs['update_fields']):
|
||||
# see if the slug has changed from the record in the db, in which case we need to
|
||||
# update url_path of self and all descendants
|
||||
old_record = Page.objects.get(id=self.id)
|
||||
if old_record.slug != self.slug:
|
||||
self.set_url_path(self.get_parent())
|
||||
update_descendant_url_paths = True
|
||||
old_url_path = old_record.url_path
|
||||
new_url_path = self.url_path
|
||||
|
||||
result = super(Page, self).save(*args, **kwargs)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue