Skip to content

fix: error occurs when searching for anything containing a full stop. #1463 - #1196

Merged
bashanlam merged 18 commits into
developfrom
1463-proposal-table-view-query-err
Oct 15, 2025
Merged

fix: error occurs when searching for anything containing a full stop. #1463#1196
bashanlam merged 18 commits into
developfrom
1463-proposal-table-view-query-err

Conversation

@bashanlam

Copy link
Copy Markdown
Contributor

Closes UserOfficeProject/issue-tracker#1463

Description

This PR fix the error occurs when searching for anything containing a full stop (e.g. bam.de) while using the instrument scientist role.

Motivation and Context

Fix the error occurs when searching for anything containing a full stop (e.g. bam.de) while using the instrument scientist role.

Changes

Update the data source to fix the error occurs when searching for anything containing a full stop (e.g. bam.de) while using the instrument scientist role.

How Has This Been Tested?

Manually

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@bashanlam
bashanlam requested review from a team, Junjiequan and simonfernandes and removed request for a team September 24, 2025 11:46
@bashanlam
bashanlam requested a review from a team as a code owner September 24, 2025 11:47
@bashanlam
bashanlam requested review from Scott-James-Hurley and deepaksftc and removed request for a team September 24, 2025 11:47
.orderBy('proposal_pk', 'desc')
.modify((query) => {
if (filter?.text) {
const jsonPath = `$[*].name ? (@.type() == "string" && @ like_regex "${filter.text}" flag "i")`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bashanlam

This is nice. I was thinking of doing a generic fix.

https://github.com/UserOfficeProject/user-office-core/blob/develop/apps/backend/src/datasources/postgres/databaseExtensions.ts

Here we have added special character escaping for non json columns. We can add one for json columns and use it across. What do you think?

This function can be applied to the default ProposalDataSource as well, if you could. Else we from ESS can take it up.

@bashanlam bashanlam Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bashanlam

This is nice. I was thinking of doing a generic fix.

https://github.com/UserOfficeProject/user-office-core/blob/develop/apps/backend/src/datasources/postgres/databaseExtensions.ts

Here we have added special character escaping for non json columns. We can add one for json columns and use it across. What do you think?

This function can be applied to the default ProposalDataSource as well, if you could. Else we from ESS can take it up.

I agree with your generic fix for this bug — it’s better than our one-off solution. Please let us know once your PR is merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bashanlam

This is nice. I was thinking of doing a generic fix.

https://github.com/UserOfficeProject/user-office-core/blob/develop/apps/backend/src/datasources/postgres/databaseExtensions.ts

Here we have added special character escaping for non json columns. We can add one for json columns and use it across. What do you think?

This function can be applied to the default ProposalDataSource as well, if you could. Else we from ESS can take it up.

@yoganandaness A generic special character escaping for json column is added.

Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated

@simonfernandes simonfernandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks nice! There are a couple of places in PostgresProposalDataSource that could also be updated with the new functions.

Reviewed

Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
@bashanlam

Copy link
Copy Markdown
Contributor Author

Looks nice! There are a couple of places in PostgresProposalDataSource that could also be updated with the new functions.

I completed testing and confirmed the new function operates solely within the current place.

@simonfernandes

Copy link
Copy Markdown
Contributor

@bashanlam I meant that you can also add these utility functions to two places in the PostgresProposalDataSource. It will fix the same problem or at least make that code neater and more understandable.

@bashanlam

Copy link
Copy Markdown
Contributor Author

@yoganandaness We've updated PostgresProposalDataSource to include the whereJsonbPathLike and orWhereJsonbPathLike functions. Could you please verify and review if this is working correctly for ESS? Thanks.

Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Co-authored-by: Simon Fernandes <simon.fernandes@stfc.ac.uk>

@yoganandaness yoganandaness left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More suggestions to make it more generic

  1. Currently, when doing json search, we are targetting only the field name. However, if we want to search other fields, we can pass it as parameter
  2. % is not needed for json search unlike normal search. Hence it can be removed

Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/postgres/databaseExtensions.ts Outdated
Comment thread apps/backend/src/datasources/stfc/StfcProposalDataSource.ts Outdated
Comment thread apps/backend/src/datasources/postgres/ProposalDataSource.ts Outdated
@yoganandaness

Copy link
Copy Markdown
Contributor

@bashanlam Was also wondering, if we could attach e2e for Instrument name search in Proposals table

bashanlam and others added 9 commits October 14, 2025 13:32
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>
Co-authored-by: Yoganandan Pandiyan <132274772+yoganandaness@users.noreply.github.com>

@yoganandaness yoganandaness left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Appreciating an e2e.

@bashanlam
bashanlam merged commit f9defb6 into develop Oct 15, 2025
36 of 37 checks passed
@bashanlam
bashanlam deleted the 1463-proposal-table-view-query-err branch October 15, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal table view query error

3 participants