Skip to content

fix(db): refuse an inline connection with no id before the cache key - #1572

Merged
cevheri merged 5 commits into
libredb:mainfrom
niukanen1:fix/1539-inline-connection-id-required
Oct 7, 2026
Merged

cevheri merged 5 commits into
libredb:mainfrom
niukanen1:fix/1539-inline-connection-id-required

Conversation

@niukanen1

Copy link
Copy Markdown
Contributor

Fixes #1539

POST /api/db/query, /api/db/health and /api/db/multi-query answered 500 INTERNAL_ERROR, "undefined is not an object (evaluating 'value.length')", for an inline connection with no id, while /api/db/test-connection answered the same record 400 CONFIG_ERROR, "Connection ID is required".

getOrCreateProvider computes its cache key before it constructs the provider, and providerCacheKey length-frames connection.id, so a missing id crashed there with a TypeError. The provider's own validate() already refuses this record with a DatabaseConfigError.

getOrCreateProvider and acquireExecutionProfileProvider now raise the same refusal ahead of their cache key, as assertReadOnlyHonoured does, so the key never sees a record the provider would refuse and no fallback key is invented for a missing id. Every route that opens a cached provider answers 400 CONFIG_ERROR and opens no socket.

Tests: the factory refuses a missing id on both entry points before anything is cached; route tests for query, health and multi-query run the real resolveConnection and factory and assert the 400 and the empty provider cache; test-connection keeps the 400 it already answered. Red on main, green with the fix.

getOrCreateProvider computed its cache key ahead of the provider, and
providerCacheKey length-frames connection.id, so an inline connection
without an id crashed there with a TypeError that the routes answered
as a 500 INTERNAL_ERROR. The provider's own validate() already refuses
this record with DatabaseConfigError, which test-connection answered
as a 400; getOrCreateProvider and acquireExecutionProfileProvider now
raise the same refusal before their cache key, so no fallback key is
invented for a missing id (libredb#1539)
@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cevheri

cevheri commented Oct 7, 2026

Copy link
Copy Markdown
Member

Hi @niukanen1
how was your libredb-studio contribute experience

whis database are using on libredb-studio (local or cloud)

@cevheri cevheri added the loop:needs-info Maintainer-loop task blocked on human-reviewed clarification label Oct 7, 2026
@niukanen1

niukanen1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

hey! the experience has been good so far, clean codebase and the provider architecture made it easy to navigate. I'm using postgres almost all the time, locally

@cevheri cevheri removed the loop:needs-info Maintainer-loop task blocked on human-reviewed clarification label Oct 7, 2026
… seed reset from its new home

The id guard was inserted between assertReadOnlyHonoured and its docblock, so the docblock attached to the new function. The route test imported @/lib/seed/config-loader, which libredb#1570 removed on main; it now imports resetCache from @/lib/seed, as the other route tests do.

@cevheri cevheri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @niukanen1, this is a clean fix. I ran it live: all ten routes from #1539 now answer 400 CONFIG_ERROR without an id, and nothing is cached or connected. Main moved under the branch, so I pushed a merge plus a small follow-up: the seed import #1570 renamed, and the readOnly docblock back on its function.

@cevheri
cevheri merged commit e3b05d1 into libredb:main Oct 7, 2026
24 checks passed
mgr-punith pushed a commit to mgr-punith/libredb-studio that referenced this pull request Oct 7, 2026
… answer 500 (D244)

Found in the review of libredb#1572: resolveConnection calls startsWith on a non-string id before the custom-connection policy check, and withOneShotTunnel hands a missing id to the tunnel pool key before validate() can refuse it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db routes: an inline connection without an id answers 500 on query, health and multi-query, 400 on test-connection

2 participants