fix: return real bucket/table IDs on dev branches (prefix-based model)#464
fix: return real bucket/table IDs on dev branches (prefix-based model)#464padak wants to merge 5 commits intokeboola:mainfrom
Conversation
Update: Branched Storage Support AddedAdded a second commit that extends the fix to also handle the branched storage model (projects where dev branches don't use prefixed bucket/table IDs). What changed1. The old logic had a bug for branched storage:
The fix mirrors how # Before (discards matching dev table):
if branch_id:
prod_table = None # gone forever
# After (saves matching dev table):
if branch_id:
if branch_id == client.branch_id:
dev_table = first_result # branched storage: keep itBonus: this also eliminates a redundant API call when querying with a prefixed dev table ID (e.g., 2. Six new branched storage tests
Verified: fails on main, passes on fix |
c01bb85 to
85e7e19
Compare
|
Updated integration tests per @Matovidlo's feedback: Now tests both branch storage models:
Feature detection: Each test run calls 10 tests total (5 per mode), all passing: Env vars: TEST_KBC_TOKEN_PREFIX=xxx # project with branched storage OFF
TEST_KBC_TOKEN_BRANCHED=yyy # project with branched storage ON
TEST_KBC_URL=https://connection.keboola.com # optional, defaults to thisTests are skipped automatically when env vars are not set. |
|
I've addressed the feedback — moved tests to I just noticed the A few things I'm not sure how to handle from outside your team:
The core fix is 3 one-line changes in |
On projects using the legacy prefix-based branch model (non-branched-storage), get_buckets and get_tables were normalizing IDs by stripping the branch prefix (e.g. out.c-15865-test → out.c-test). These normalized IDs don't physically exist and break downstream tool calls that reference them. Keep prod_id for internal deduplication but return real Storage API IDs. Fixes keboola/keboola_agent_cli#113
In the branched storage model, dev branch tables have the same IDs as production and are distinguished only by KBC.createdBy.branch.id metadata. The old _get_table logic discarded any table with branch metadata during the initial lookup, then tried a prefixed ID that doesn't exist in branched storage — resulting in "table not found" for valid tables. Fix mirrors _find_buckets pattern: when the first lookup returns a table whose branch_id matches client.branch_id, treat it as the dev table directly instead of discarding it. Also adds 6 branched storage tests covering get_bucket, get_buckets, get_table, and get_tables for projects without prefix-based IDs.
Runs against a real Keboola project with branched storage OFF (prefix-based model). Creates a dev branch, bucket, and table, then verifies that get_buckets and get_tables return real physical IDs — not stripped prod_id values that would break downstream API calls. 5 tests: - get_bucket_by_id returns the same ID that was passed in - list_all_buckets includes dev-branch bucket with real ID - returned bucket ID works in subsequent API calls (bucket_detail) - get_tables returns real table ID - returned table ID works in subsequent API calls (table_detail) Requires TEST_STORAGE_TOKEN and TEST_STORAGE_API_URL env vars. Skipped automatically when env vars are not set.
Parametrized tests now run against two real projects:
- prefix-based (branched storage OFF): bucket IDs have c-{branch_id}- prefix
- branched-storage (ON): bucket IDs identical to production
Also verifies project features via token/verify to ensure the test
project matches the expected mode. Uses TEST_KBC_TOKEN_PREFIX and
TEST_KBC_TOKEN_BRANCHED env vars (skipped when not set).
10 tests total (5 per mode), all passing.
Addresses review feedback: - Moved from tests/ to integtests/ (proper location for integration tests) - Uses standard INTEGTEST_STORAGE_TOKENS pool instead of custom env vars - Detects storage-branches feature via tokens/verify to classify project - No skipping: tests run against whatever project the pool provides - Removed standalone test_integration_branches.py from tests/ The test creates a dev branch + bucket + table, calls get_buckets/get_tables via MCP tools, and verifies returned IDs are real physical IDs that work in subsequent API calls. Both prefix-based and branched-storage models are covered (depending on which projects are in the pool).
2dfc305 to
5a7e60d
Compare
Summary
On projects using the legacy prefix-based branch model (non-branched-storage),
get_buckets,get_table, andget_tableswere normalizing bucket/table IDs by stripping the branch prefix (e.g.out.c-15865-testbecameout.c-test). These normalized IDs don't physically exist in the Storage API and break all downstream tool calls that reference them.Root cause:
_combine_buckets,_get_table, and_list_tablesintools/storage/tools.pywere replacing the realidfield withprod_id(the stripped version) when returning results for dev-branch-only buckets/tables.Fix: Stop overwriting
idwithprod_idin the output. Theprod_idfield is preserved for internal deduplication logic (dict key in_list_tablesfor merging prod+dev tables of the same logical table), but theidfield returned to the caller is now always the real, physical Storage API ID.Changes
_combine_buckets(dev-only bucket case): removed'id': dev_bucket.prod_idfrommodel_copyupdate_get_table: removed'id': table.prod_idfrommodel_copyupdate_list_tables(dev bucket tables): removed'id': table.prod_idfrommodel_copyupdateFixes keboola/keboola_agent_cli#113
Test plan
tests/tools/storage/test_tools.pypasstest_get_bucketdev-only case now expects real prefixed IDtest_get_bucketsdev branch case now expects real prefixed IDtest_get_tabledev branch cases (3 parametrizations) now expect real prefixed IDstest_get_tablesdev branch case now expects real prefixed IDs for both emails and assets