Repository navigation
Commit 0fa4bb4
committed
Fix catalog case mismatch: switch to REQUIRES_SET_CATALOG + no-op set_current_catalog
Root cause: the set_catalog decorator in shared.py:346 does a raw case-sensitive ==
comparison between catalog_name (extracted from a SQL expression) and
_default_catalog (stored at adapter construction time). Because the Db2 sqlglot
dialect uses UPPERCASE normalisation, model names built with dialect='db2' always
produce uppercase catalog identifiers (e.g. 'TESTDB'). However tests that call
ctx.create_context() use default_dialect='duckdb' (LOWERCASE), which lowercases
model names to 'testdb'. These two cases cannot both match a single static
_default_catalog string — the comparison is structurally broken for Db2.
Fix: switch catalog_support from SINGLE_CATALOG_ONLY to REQUIRES_SET_CATALOG.
The REQUIRES_SET_CATALOG path in shared.py calls get_current_catalog() at runtime
and compares the live value against catalog_name. Since get_current_catalog()
returns uppercase ('TESTDB') to match the Db2 dialect:
- When catalog_name == 'TESTDB' (db2-dialect context): match, no set_current_catalog call
- When catalog_name == 'testdb' (duckdb-dialect context): no match, set_current_catalog
is called — which is a no-op since Db2 cannot switch catalogs at runtime
In both cases the catalog is always stripped from DDL before it reaches Db2 (the
catalog stripping happens earlier in the decorator regardless of catalog_support).
So neither path causes any SQL error.
Also revert the previous two incorrect lower() fixes:
- get_current_catalog() back to .upper() (Db2 CURRENT SERVER is always uppercase)
- Db2ConnectionConfig.get_catalog() back to .upper() (matches dialect normalisation)
Update test_db2.py:
- test_get_current_catalog: assert result == 'TESTDB' (was 'testdb')
- test_catalog_support: assert REQUIRES_SET_CATALOG (was SINGLE_CATALOG_ONLY)1 parent 70b0937 commit 0fa4bb4
3 files changed
Lines changed: 41 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2650 | 2650 | | |
2651 | 2651 | | |
2652 | 2652 | | |
2653 | | - | |
2654 | | - | |
2655 | | - | |
2656 | | - | |
2657 | | - | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
2658 | 2657 | | |
2659 | | - | |
| 2658 | + | |
2660 | 2659 | | |
2661 | 2660 | | |
2662 | 2661 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
100 | | - | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
| |||
446 | 454 | | |
447 | 455 | | |
448 | 456 | | |
449 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
450 | 469 | | |
451 | 470 | | |
452 | 471 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
378 | | - | |
379 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
380 | 381 | | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
385 | | - | |
| 386 | + | |
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
| |||
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
428 | | - | |
429 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
430 | 433 | | |
431 | 434 | | |
432 | 435 | | |
| |||
0 commit comments