Repository navigation
[Server] Return INVALID_ARGUMENT for PostgreSQL limit errors and upgrade the driver to 42.7.14 - #1993
Conversation
8c0dbaf to
148395f
Compare
a8dd80d to
434131d
Compare
timothyw553
left a comment
There was a problem hiding this comment.
Thanks @shba24 for the contribution. Generally looks good, please have a look at my one comment.
|
/review |
|
@shba24 I have stamped the PR but could you take a look at the AI review? https://github.com/unitycatalog/unitycatalog/pull/1993/checks?check_run_id=117204846578 |
|
Thanks @timothyw553 for the stamp! I went through the three AI notes. My take is below; tell me if you see any of them differently. 1. A driver operators added before. Agreed. I pushed 4a89e5d, which adds one line to the PostgreSQL prerequisites in 2. The 3. The driver pinned in two places. I'd keep both lines, because they do different things. The direct dependency makes the server ship the driver. |
Creating a staging table whose location is longer than PostgreSQL's 2,704-byte limit on an index entry returned a 500. This can happen when the catalog and schema have no storage location and storage-root.tables is long. DatabaseErrors lists database errors by database, SQLSTATE and the error code to return. TransactionManager uses that code and falls back to INTERNAL. The only entry is PostgreSQL's 54000 (program_limit_exceeded), mapped to INVALID_ARGUMENT. The message is unchanged. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
The server ships the PostgreSQL driver that jdbc-adapter brings in, 42.7.2, which is affected by CVE-2026-42198. Declare the driver as a direct dependency at 42.7.14 so the server and the tests use the same version, and fix the deployment guide, which asked users to add a driver the server already ships. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
4a89e5d to
58faa91
Compare
|
AI review, run locally (#1993) I ran this repository's AI reviewer locally: the six roles in Reviewed head: 58faa91 (current head).
|
|
/review |
The guide named jdbc-adapter 2.7.0, but the build uses 2.13.0. Name the adapter without a version so the text stays correct on upgrades. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
Re: AI review (today's run) Thanks. My take on each; tell me if you see any differently:
|
|
/review |
Notes that DatabaseErrors entries match dialect subclasses and the whole 54000 code, explains the PostgreSQL dependencyOverrides entry, and states the deployment guide's driver rule directly. Co-authored-by: Isaac <[email protected]> Signed-off-by: Shubham Bansal <[email protected]>
|
/review |
|
Re: AI review (68a0ac7) Addressed in 7fb2387:
No change needed for the rest:
|
PR Checklist
docsis updatedDescription of changes
This PR makes two changes for running the server on PostgreSQL.
1. Return 400 when a value exceeds a PostgreSQL limit
On PostgreSQL, creating a staging table with a very long location returns a 500:
PostgreSQL limits an index entry to 2,704 bytes, and
staging_locationis indexed. The request caused the error, so the server should return 400.The new
DatabaseErrorslists database errors by database, SQLSTATE and the error code to return.TransactionManageruses that code and falls back toINTERNAL. The only entry is PostgreSQL's54000(program_limit_exceeded), mapped toINVALID_ARGUMENT. Every other database error is stillINTERNAL, and the message is unchanged.2. Upgrade the PostgreSQL JDBC driver to 42.7.14
The server ships driver 42.7.2 because
jdbc-adapter2.13.0 depends on it. That version is affected by CVE-2026-42198, fixed in 42.7.11. Tests use a different version, 42.7.13. This PR pins the driver to 42.7.14 as a server dependency and removes the test-only line, so the server and the tests use the same driver.The deployment guide told PostgreSQL users to download the driver and add it to
jars/classpath. The server already ships one, so following it put two drivers on the classpath. The guide now says the server ships the driver.User impact
TransactionManager;ModelRepositorymanages its own transactions and still returnsINTERNAL. Nothing that works today changes.Tests
TransactionManagerTest.testDatabaseErrorCode:54000on PostgreSQL isINVALID_ARGUMENT;54000on H2 and another SQLSTATE on PostgreSQL stayINTERNAL.TransactionManagerTest.testDatabaseErrorWithoutSqlStateIsInternalandtestTransactionWithRuntimeException: a database error without a SQLSTATE, and an error that isn't from the database, stayINTERNAL.PostgresDeltaCommitsCRUDTest.testValueOverIndexLimitIsInvalidArgument(Testcontainers): inserting a staging table whose location is over the index limit on real PostgreSQL givesINVALID_ARGUMENT. It fails without this change.build/sbt test) passes.📐 Design notes & details
When the error happens
/tables/<uuid>. Catalog and schema storage locations are at most 255 characters, so locations under them fit.<storage-root.tables>/__unitystorage, and that property has no length limit.staging_locationisvarchar(2048), which counts characters, while the index limit counts bytes. So only multi-byte characters can reach the index limit. PostgreSQL also compresses an index entry before checking its size, so repetitive values can be longer and still fit.Why map the error instead of adding a limit
ExternalLocationUtilsruns aLIKE 'prefix%'query onstaging_location, which a hash index can't serve.400 for a configuration-caused error
storage-root.tables, which an operator sets, so the client sending the request can't fix it. It is still a 400: the server is working, and retrying the same request fails the same way. Alerts on 5xx won't see these requests.How the error is recognized
PostgreSQLDialect.class.isInstance(...)also matches subclasses.SQLExceptionamong the exception's causes, so it works whether the error comes frompersistor fromcommit. The message is not parsed.DatabaseErrors.Test values
TransactionManagerinstead of the API, so it doesn't need a longstorage-root.tables, and it reuses the existing PostgreSQL container.Driver
mainalready shipspostgresql-42.7.2.jarinjars/classpath, so deployments may rely on the bundled driver. Excluding it would break them on upgrade. pgjdbc is BSD-2-Clause.jdbc-adapterdoesn't use the driver directly. Its classes have no references toorg.postgresql, and it gets connections from the DataSource we pass in, so it needs no upgrade.dependencyOverrides, so a dependency that brings another version, such as 42.7.2 fromjdbc-adapter, can't change it.server/Runtime/externalDependencyClasspathandserver/Test/externalDependencyClasspatheach contain one driver,postgresql-42.7.14.jar.This pull request and its description were written by Isaac.