-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add support for paginating elasticsearch queries for django_tables2
(with HTMX)
#35712
Conversation
this will be used in other areas to maintain consistency with case list explorer report sorting
this ElasticRecord will support only CaseSearchES for now, as that's what we will need in the near future for data cleaning cases
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.
Love the documentation
|
||
@property | ||
@abstractmethod | ||
def verbose_name_plural(self): |
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.
Perhaps the default implementation could just add a 's' to the verbose_name.
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'm following requirements of the base models from django_tables2
, and that's not always the case with translated text that plurals end in s, in english or other languages
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.
Emphasis on default. But ok.
def __init__(self, **kwargs): | ||
data = kwargs.pop('data') | ||
if not ElasticTableData.validate(data): | ||
raise ValueError( |
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.
👍
if isinstance(original_exception, TransportError): | ||
if hasattr(original_exception.info, "get"): | ||
if original_exception.info.get('status') == 400: | ||
raise BadRequestError() |
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.
Does TransportError
have any other data in it about what went wrong? I don't like the idea of erasing that and potentially only logging a BadRequestError, which does not give you much to work with when investigating 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.
i'm following the pattern we use with CaseListExplorer
for fetching results
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.
That does not mean we cannot improve on it.
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 table this
if isinstance(original_exception, TransportError): | ||
if hasattr(original_exception.info, "get"): | ||
if original_exception.info.get('status') == 400: | ||
raise BadRequestError() |
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.
That does not mean we cannot improve on it.
Technical Summary
This adds support for paginating elasticsearch queries with
django_tables2
with the introduction of theElasticTable
class that hooks into theElasticTableData
class that handles the ordering and pagination of the query based on theElasticTable
'srecord_class
passed to it.The first
ElasticRecord
implementation is forCaseSearchES
withCaseSearchElasticRecord
. From this example, you can see how easy it would be to extend this support for other queries, likeFormES
See this commit for how we would create a simple
HTMX
+django_tables2
view with cases fromCaseSearchES
: badb29dSafety Assurance
Safety story
There is no production workflow using these changes yet. The bit of code that was extracted from
CaseListExplorer
should be very easy to identify that it's safe without needing QA. As a sanity check I made sureCaseListExplorer
sorted on@case_id
with no issue.Automated test coverage
I've added new tests.
QA Plan
Not needed
Rollback instructions
Labels & Review