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

Unique indexes create server errors rather than form validation notices #10674

Open
NightJar opened this issue Jan 31, 2023 · 2 comments
Open

Comments

@NightJar
Copy link
Contributor

NightJar commented Jan 31, 2023

Affected Version

At least 4.11, possibly earlier versions (untested).
This may have worked in previous versions, as the way mysqli errors are delivered has changed in PHP 8, which may be the cause of this. c.f. #10570 for more detail.

Description

When marking a field as unique via the use of an index constraint, uncaught exceptions are thrown on a failed write due to a duplicate value. This causes an unfriendly system halt and "Server error" to be shown, as opposed to normal form feedback (e.g. in the CMS).

Steps to Reproduce

With both Framework & Admin installed:
Make a DataObject with a title field & unique index on Title
Make a ModelAdmin for that DataObject
Create an instance of the DataObject via the ModelAdmin with the Title "test"
Try to create a second instance of the DataObject via the ModelAdmin with the Title "test"

👀 "server error" toast message with no further info on how to validate the form.

@GuySartorelli
Copy link
Member

Just to be clear, you've mentioned mysqli in passing but haven't explicitly said whether this issue is explicitly related only to mysqli. So does this also happen with other connectors? Or only mysqli?

@NightJar
Copy link
Contributor Author

NightJar commented Feb 7, 2023

does this also happen with other connectors?

I don't know. It is not my situation, other adaptors can be considered outside scope of this issue.
MySQL is the default & only supported connector (afaik), which uses the PHP mysqli library.

If the intention is to throw the framework generic DatabaseException then it isn't really of concern - other adaptors should also throw them in a similar circumstance. How the framework handles that in various circumstances shouldn't matter on the underlying library.

My intention with the comment was to perhaps provide a little "starting context" on how this problem exists. Unfortunately it may have distracted from the core of the issue, which is that a unique index gives a very poor experience when handling conflicts. Both as a developer and an administrator - arguably this could have been an issue on the CMS repo, but I think the issue is more relevant to validation issues in general than to usage of the CMS. I.e. SilverStripe\ORM\ValidationException and maybe Forms in general rather than CMSAdmin::EditForm or low-level database adaptor logic.

I suppose one might reframe the issue as:

  • There is framework allowing me to create unique indexes.
  • There is no framework around using unique indexes.

I see this as a gap in what the framework offers and thus should be extended to include.

I hope that clarifies :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants