-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix issue with outdated tag set in document index (#1331) #1332
Changes from 6 commits
1598e2d
a4b95ed
32818d3
784b2da
fbc8759
b3ffaab
b1c898c
565be05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -428,6 +428,7 @@ class DocumentSignalHandlers: | |||||
"fragment": "fragments", | ||||||
"tag": "tags", | ||||||
"document type": "doctype", | ||||||
"tagged item": "tagged_items", | ||||||
"Related Fragment": "textblock", # textblock verbose name | ||||||
"footnote": "footnotes", | ||||||
"source": "footnotes__source", | ||||||
|
@@ -485,6 +486,15 @@ def unidecode_tag(sender, instance, **kwargs): | |||||
"""Convert saved tags to ascii, stripping diacritics.""" | ||||||
instance.name = unidecode(instance.name) | ||||||
|
||||||
@staticmethod | ||||||
def tagged_item_change(sender, instance, action, **kwargs): | ||||||
"""Ensure document is indexed after the tags m2m relationship is saved and the list | ||||||
of tags is refreshed from the database, on any tag change.""" | ||||||
if action in ["post_add", "post_remove", "post_clear"]: | ||||||
logger.debug("taggit.TaggedItem %s, reindexing related document", action) | ||||||
instance.refresh_from_db() | ||||||
ModelIndexable.index_items([instance]) | ||||||
|
||||||
|
||||||
class DocumentQuerySet(MultilingualQuerySet): | ||||||
def metadata_prefetch(self): | ||||||
|
@@ -1219,10 +1229,6 @@ def index_data(self): | |||||
"post_save": DocumentSignalHandlers.related_save, | ||||||
"pre_delete": DocumentSignalHandlers.related_delete, | ||||||
}, | ||||||
"tags": { | ||||||
"post_save": DocumentSignalHandlers.related_save, | ||||||
"pre_delete": DocumentSignalHandlers.related_delete, | ||||||
}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need these handlers, though, right? If someone renames a tag without changing any m2m relationships, we should reindex all the documents with that renamed tag so they reflect the update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Added back. |
||||||
"doctype": { | ||||||
"post_save": DocumentSignalHandlers.related_save, | ||||||
"pre_delete": DocumentSignalHandlers.related_delete, | ||||||
|
@@ -1262,9 +1268,6 @@ def merge_with(self, merge_docs, rationale, user=None): | |||||
metadata into this document, adds the merged documents into | ||||||
list of old PGP IDs, and creates a log entry documenting | ||||||
the merge, including the rationale.""" | ||||||
# initialize old pgpid list if previously unset | ||||||
if self.old_pgpids is None: | ||||||
self.old_pgpids = [] | ||||||
|
||||||
# if user is not specified, log entry will be associated with | ||||||
# script and document will be flagged for review | ||||||
|
@@ -1287,10 +1290,15 @@ def merge_with(self, merge_docs, rationale, user=None): | |||||
needs_review = [self.needs_review] if self.needs_review else [] | ||||||
|
||||||
for doc in merge_docs: | ||||||
# add merge id to old pgpid list | ||||||
self.old_pgpids.append(doc.id) | ||||||
# add any tags from merge document tags to primary doc | ||||||
# NOTE: This must be done before any other changes to self because it will fire | ||||||
# m2m_changed signal which calls self.refresh_from_db() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this refresh from db likely to be problematic elsewhere? it seems like it could lead to unexpected behavior that might be hard to troubleshoot in the signal handler, instead of refreshing, could we get a new instance from the db without modifying the local copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea, much better than refresh from db, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, this (or adding back the geniza/geniza/corpus/tests/conftest.py Lines 60 to 61 in 565be05
Not sure what's going on here because it seems like |
||||||
self.tags.add(*doc.tags.names()) | ||||||
# initialize old pgpid list if previously unset | ||||||
if self.old_pgpids is None: | ||||||
self.old_pgpids = [] | ||||||
# add merge id to old pgpid list | ||||||
self.old_pgpids.append(doc.id) | ||||||
# add description if set and not duplicated | ||||||
# for all supported languages | ||||||
for lang_code in language_codes: | ||||||
|
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 instance here is the document with the m2m relation?
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.
Yes! Added comment to clarify.