Skip to content

Enhancement: Add validation for unique values for a short text fields #1770

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Koc
Copy link
Contributor

@Koc Koc commented Apr 24, 2025

This PR adds new toggle that validates short text fields for unique values. Closes #660

🔍 Preview

image

Trying to insert row with value that already present in table
image

@Koc Koc requested review from enjeck and blizzz as code owners April 24, 2025 18:34
@Koc Koc force-pushed the feature/add-unique-values branch from 4bcc937 to 8f0684a Compare April 24, 2025 22:39
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

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

Didn't test yet, so far looks good, left minor requests.

However, existing tests seem to be failing. Having additional tests, integration, e2e or both would be appreciated.

@blizzz blizzz added enhancement New feature or request 2. developing Work in progress labels Apr 28, 2025
@Koc Koc force-pushed the feature/add-unique-values branch from 8f0684a to 12a33b3 Compare April 30, 2025 11:01
@Koc Koc force-pushed the feature/add-unique-values branch 4 times, most recently from 276e95d to 7a20c4b Compare May 10, 2025 15:41
@Koc
Copy link
Contributor Author

Koc commented May 10, 2025

@blizzz I've updated PR and 1st message including screenshoots. Now we have user-friendly error message with an explanation why row wasn't added. Old tests should pass.

Also I'm trying to add new integration tests here. If anybody can help me with that - welcome

@Koc Koc force-pushed the feature/add-unique-values branch 4 times, most recently from a3d3049 to adf32d1 Compare May 10, 2025 22:56
@Koc
Copy link
Contributor Author

Koc commented May 10, 2025

@blizzz Old tests fixed. Also there is 1 integration test for a new functionality

Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

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

A few questions.

I did a little bit of smoke testing, and it looks good so far 👍

Three more points I like to raise from this review:

  1. There is one corner case though: when you have a column with non-unique values, but edit the column and set it to unique, then it works. But obviously the content there is not unique, but new values will be checked for it.

Is this intentional behaviour? An alternative would be to reject the change with the error that the column values are not unique.

  1. Another thought came up about the return status code. You set it to 400, which is OK, I am thinking 409 could maybe be more precise. But maybe this is also bike shedding 🤔

  2. When you try to update a row to have a duplicated value, the operations fails , but with status code 500 instead of 400. This should be sorted out.

I hope I've covered all points now 🙇 Thank you for the work on this feature!

return new DataResponse(['message' => $this->n->t('An error caused by an invalid request occurred. More details can be found in the logs. Please reach out to your administration.')], Http::STATUS_BAD_REQUEST);
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we remove the translated error string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because now we're providing not generic error message but more self-explanatory Column "My unique column" contains not unique value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

That's true, but the exception message is not translated either. They should not be translated for the log, but user facing messages should be translated (they can be specific of course, that is an improvement 🙂).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've refactored it a bit and added optional translatedMessage property to the BadRequestError exception.

@Koc
Copy link
Contributor Author

Koc commented May 13, 2025

@blizzz thank you for code review and deep testing 🫶 . I'm going to fix your finding later today

@Koc Koc force-pushed the feature/add-unique-values branch 6 times, most recently from 36f6088 to 52d3fab Compare May 14, 2025 15:29
@Koc
Copy link
Contributor Author

Koc commented May 14, 2025

hey @blizzz!

  1. But obviously the content there is not unique, but new values will be checked for it.

Yeah, this is expected behavior. We can improve it later, but as you can see - current PR already huge.

  1. Let's keep 400 for now and think about changing it later? It can be http 409 or 422

  2. I've improved editing column with non-unique value:

  • Now we have 1 single clear message. Previously we have 2 abstract messages that not help at all

    🔍 Preview

    image

  • We don't close popup window in order to not loose possible unsaved changes

  • Http response has code 400 instead of 500

  • Changes covered with behat tests

@Koc Koc force-pushed the feature/add-unique-values branch 3 times, most recently from 35cd347 to 0f62241 Compare May 14, 2025 15:49
@Koc
Copy link
Contributor Author

Koc commented May 20, 2025

Can we merge @blizzz @enjeck ? 🙏

@enjeck
Copy link
Contributor

enjeck commented May 21, 2025

Can we merge @blizzz @enjeck ? 🙏

It's unrelated to this, but I'd prefer to hold off on any merges until some cypress issues are fixed. Right now, Cypress tests fail everywhere and I'd like to fix that first, just to be safe

@blizzz
Copy link
Member

blizzz commented May 23, 2025

Can we merge @blizzz @enjeck ? 🙏

It's unrelated to this, but I'd prefer to hold off on any merges until some cypress issues are fixed. Right now, Cypress tests fail everywhere and I'd like to fix that first, just to be safe

Cypress one`s should hopefully be fixed now with #1809@Koc could you rebase?

@Koc Koc force-pushed the feature/add-unique-values branch from 0f62241 to 3a9c5bc Compare May 23, 2025 22:14
@Koc
Copy link
Contributor Author

Koc commented May 23, 2025

rebased. Almost green

@Koc
Copy link
Contributor Author

Koc commented May 25, 2025

seems like we have same error in other PRs: https://github.com/nextcloud/tables/actions/runs/15216779497/job/42804024347

@Koc Koc force-pushed the feature/add-unique-values branch from 3a9c5bc to 4cf6dca Compare May 27, 2025 12:41
@Koc
Copy link
Contributor Author

Koc commented May 27, 2025

So, we have completely green pipeline including Cypress @blizzz @enjeck

Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

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

please see comments

return new DataResponse(['message' => $this->n->t('An error caused by an invalid request occurred. More details can be found in the logs. Please reach out to your administration.')], Http::STATUS_BAD_REQUEST);
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
Copy link
Member

Choose a reason for hiding this comment

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

That's true, but the exception message is not translated either. They should not be translated for the log, but user facing messages should be translated (they can be specific of course, that is an improvement 🙂).

@Koc Koc force-pushed the feature/add-unique-values branch 2 times, most recently from d49fd28 to 26a11d8 Compare June 23, 2025 16:04
…code review fixes)

Signed-off-by: Kostiantyn Miakshyn <[email protected]>
@Koc Koc force-pushed the feature/add-unique-values branch from 26a11d8 to 119e66b Compare June 23, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UNIQUE constraint on columns
3 participants