Skip to content
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 search index updates for AbstractFilterPages #8468

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

chosak
Copy link
Member

@chosak chosak commented Jun 12, 2024

We have a bug whereby AbstractFilterPage deletes (and, presumably, updates) don't get reflected in the filterable list search index. This happens because of some logic around Wagtail specific page types; see internal
https://github.local/Design-Development/Design-and-Content-Team/issues/471 for details.

Our current code hooks up Wagtail Page save/delete events to django-opensearch-dsl save/delete handlers but, before passing along the events, casts AbstractFilterPage instances to their specific page type. This prevents the d-o-d logic from actually updating the search index because it can't associate a specific page model type with any particular document/index.

With this change, we do two things:

  1. Ensure that pages are cast to their AbstractFilterPage versions, thus ensuring that d-o-d knows how to index them.
  2. Modify FilterablePagesDocument.update() so that, at the moment we are trying to update the search index, we ensure that we are using the most specific version of the page.

Notes and todos

This approach does have one drawback which is that it prevents us from, theoretically, having some other d-o-d search index for a more specific page type. It would definitely be nicer if d-o-d supported inherited model types and thus knew to update the AbstractFilterPage index when a BlogPage is updated.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code follows the standards laid out in the CFPB development guidelines

We have a bug whereby AbstractFilterPage deletes (and, presumably,
updates) don't get reflected in the filterable list search index. This
happens because of some logic around Wagtail specific page types; see
internal
https://github.local/Design-Development/Design-and-Content-Team/issues/471
for details.

Our current code hooks up Wagtail Page save/delete events to
django-opensearch-dsl save/delete handlers but, before passing along
the events, casts AbstractFilterPage instances to their specific page
type. This prevents the d-o-d logic from actually updating the search
index because it can't associate a specific page model type with any
particular document/index.

With this change, we do two things:

1. Ensure that pages are cast to their AbstractFilterPage versions,
thus ensuring that d-o-d knows how to index them.
2. Modify FilterablePagesDocument.update() so that, at the moment we
are trying to update the search index, we ensure that we are using the
most specific version of the page.
@chosak chosak requested a review from willbarton June 12, 2024 20:54
Copy link
Member

@willbarton willbarton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good approach around the upstream issue with subclasses, and I've confirmed it fixes the issue where saves/deletes of existing pages aren't removed from the index 👍

@chosak chosak added this pull request to the merge queue Jun 14, 2024
Merged via the queue into main with commit 3f573de Jun 14, 2024
12 checks passed
@chosak chosak deleted the fix/search-index-updates branch June 14, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants