-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix: handle column default types correctly in SchemaCache #3750
Conversation
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.
Thanks for the PR. Here are my observations:
src/PostgREST/SchemaCache.hs
Outdated
WHEN ad.adbin IS NOT NULL THEN pg_get_expr(ad.adbin, ad.adrelid)::text | ||
ELSE NULL -- Handle cases where none of the conditions are met |
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.
This still gives the same result since select pg_get_expr(null,null)
returns null
. What we need here is to get the column default before the domain default.
A test is needed to verify that changes work. Something similar to this one, but with another table with a column that overrides the domain default (like the one mentioned in the issue):
postgrest/test/spec/Feature/Query/InsertSpec.hs
Lines 566 to 573 in 5ca969f
it "inserts a default on a DOMAIN with default" $ | |
request methodPost "/evil_friends?columns=id,name" [("Prefer", "return=representation"), ("Prefer", "missing=default")] | |
[json| { "name": "Lu" } |] | |
`shouldRespondWith` | |
[json| [{"id": 666, "name": "Lu"}] |] | |
{ matchStatus = 201 | |
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"] | |
} |
CHANGELOG.md
Outdated
### Unreleased | ||
- **fix**: Improved handling of column default values in `SchemaCache`. This addresses issue #3706 by ensuring all relevant cases are covered, including scenarios where `ad.adbin` is not NULL. |
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.
There is already an "Unreleased" section at the beginning of the document. The entry should go under the "Fixed" subtitle. Check the other entries for the format.
@laurenceisla , |
### Fixed | ||
- **fix**: Improved handling of column default values in `SchemaCache`. This addresses issue #3706 by ensuring all relevant cases are covered, including scenarios where `ad.adbin` is not NULL. | ||
|
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.
There is already a Fixed
h3-section under the Unreleased h2-section. It should be added to that section. Also you are still not following the format as the other log entries below. Have a close look where the issue number is placed, note that the author is listed at the end, etc...
it "inserts a default on a DOMAIN with default" $ | ||
request methodPost "/evil_friends?columns=id,name" | ||
[("Prefer", "return=representation"), ("Prefer", "missing=default")] | ||
[json| { "name": "Lu" } |] | ||
`shouldRespondWith` | ||
[json| [{"id": 666, "name": "Lu"}] |] | ||
{ matchStatus = 201 | ||
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"] | ||
} | ||
|
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.
Laurence asked you to write a test-case similar to this one, but with some changes (i.e. test for column default, not domain default)...
Instead of adjusting the test-case, so that it actually matches what you are trying to achieve.. you just copy-pasted the exact same thing, which is a duplicate of the test-case right after.
What are you trying to achieve?
Also note that all tests are failing, because your SQL is invalid + the style check is not passing either. |
This pull request addresses issue #3706 by improving the handling of column default values in the SchemaCache.
The previous implementation did not correctly account for certain data types, which could lead to incorrect metadata retrieval.
This fix ensures that all relevant cases are covered, including scenarios where
ad.adbin
is not NULL.Additionally, an entry has been added to the CHANGELOG.md for this fix.
Fixes #3706