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

DatabaseRule "unique" fails quietly when given an incorrect column #52456

Closed
woganmay opened this issue Aug 12, 2024 · 4 comments
Closed

DatabaseRule "unique" fails quietly when given an incorrect column #52456

woganmay opened this issue Aug 12, 2024 · 4 comments

Comments

@woganmay
Copy link

woganmay commented Aug 12, 2024

Laravel Version

11.20.0

PHP Version

8.3.6

Database Driver & Version

PostgreSQL 16

Description

If I write a validation rule for a non-existent table, for eg:

$validator = Validator::make(request()->all(), [
  'port' => 'required|integer|unique:nonexistent,port',
]);

The validator crashes with SQLSTATE[HY000]: General error: 1 no such table: nonexistent which is good enough. However, if I specify an existing table but a non-existent column, no errors or exceptions are thrown.

Steps To Reproduce

To reproduce this bug:

  • Create any table
  • Create a validator that uses the unique: rule
  • Specify a valid database name but an invalid column name
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@Lakshan-Madushanka
Copy link

Lakshan-Madushanka commented Aug 16, 2024

I have experience this issue several time and this can cause unexpected behavior and issues. So I opened a pull request #52500 which I wanted to do a while ago. Unfortunately it has been delayed merging.

@withgem
Copy link

withgem commented Aug 16, 2024

I believe the expected behavior should be to throw an error when an invalid column is specified. I reviewed @Lakshan-Madushanka's pull request #52500, and it seems to address this issue effectively.

@driesvints
Copy link
Member

I don't think there's any action for us to take here as it's expected you provide a correct column name.

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

5 participants