Skip to content

fix: data sources with same name but different paths overriding data - #417

Open
M4nuF wants to merge 2 commits into
open-policy-agent:mainfrom
M4nuF:bugfix/416-data-source-primary-key-include-path
Open

M4nuF wants to merge 2 commits into
open-policy-agent:mainfrom
M4nuF:bugfix/416-data-source-primary-key-include-path

Conversation

@M4nuF

@M4nuF M4nuF commented Sep 10, 2026

Copy link
Copy Markdown

Fix: data sources with the same name but different path silently overwrite each other

Fixes #416

Changes

  • Widen sources_datasources primary key to (source_id, name, path) via new migration (recreate table across sqlite/postgres/mysql/cockroachdb).
  • Update UpsertSource's conflict key to (source_id, name, path).
  • Fix Datasources.Equal to key by (Name, Path) instead of Name alone.
  • Add regression test covering two datasources with the same name but different paths.

Testing

  • go test ./... (sqlite, postgres, mysql, cockroachdb via testcontainers) — all pass.

@M4nuF
M4nuF force-pushed the bugfix/416-data-source-primary-key-include-path branch from 8e3e744 to abe08d6 Compare September 10, 2026 07:10
@srenatus

Copy link
Copy Markdown
Contributor

Heya. Thanks for working on a fix. Easy things first: DCO needs to be adjusted on the commits.

Harder things: there might be other places where a data source is referenced by name only -- like https://github.com/open-policy-agent/opa-control-plane/blob/main/pkg/service/worker.go#L174-L183. Can you add some sort of e2e test so we know that it'll actually work? 💦

Thanks again 🎈

Comment thread internal/migrations/migrations_next.go Outdated
fmt.Sprintf("%03d_fix_datasources_primary_key_rename.up.sql", offset): "ALTER TABLE sources_datasources RENAME TO " + oldName,
fmt.Sprintf("%03d_fix_datasources_primary_key_create.up.sql", offset+1): strings.TrimRight(newTbl.SQL(kind), ";"),
fmt.Sprintf("%03d_fix_datasources_primary_key_copy.up.sql", offset+2): fmt.Sprintf(`INSERT INTO sources_datasources (%[1]s) SELECT %[1]s FROM %[2]s`, cols, oldName),
fmt.Sprintf("%03d_fix_datasources_primary_key_drop.up.sql", offset+3): "DROP TABLE " + oldName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we have one txn per file -- can we put this into a single transaction to avoid inconsistencies on failure? 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review!

• DCO: fixed
•  worker.go : Tried to address this by adding a datasourcePath field to sourceSynchronizer metadata is now nested by name -> path when names collide
• E2E test: added TestBundleWorkerExecute_DuplicateDatasourceNamesDisambiguatedByPath in  worker_test.go

Let me know if this properly addresses your comments or something else is required.

@M4nuF
M4nuF force-pushed the bugfix/416-data-source-primary-key-include-path branch from abe08d6 to 795ac6b Compare October 2, 2026 09:05
Signed-off-by: Manuel Feyrer <manuel.feyrer@zeiss.com>
@M4nuF
M4nuF force-pushed the bugfix/416-data-source-primary-key-include-path branch from 795ac6b to c4e9c3d Compare October 2, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data sources with the same name but different path silently overwrite each other

2 participants