Skip to content

fix: atomize metadata map - #77

Open
vittorio-reinaudo wants to merge 2 commits into
mainfrom
fix/atomize-metadata
Open

fix: atomize metadata map#77
vittorio-reinaudo wants to merge 2 commits into
mainfrom
fix/atomize-metadata

Conversation

@vittorio-reinaudo

@vittorio-reinaudo vittorio-reinaudo commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Bug: transaction flag in metadata never read due to atom/string key mismatch

In arke lib, in_transaction/2 (used by QueryManager) checks arke.metadata for a :transaction key using an atom:

Map.get(arke.metadata || %{}, :transaction, true) == false

However, metadata is not parsed into atom keys — it's loaded with string keys (e.g. "transaction"). As a result, Map.get/3 always misses and falls back to the default (true), so the transaction: false option in metadata is silently ignored and every call runs inside a transaction regardless of what's configured.

Suggested fix: either parse metadata keys to atoms before this check, or look up the string key directly (e.g. Map.get(arke.metadata || %{}, "transaction", true)), depending on how metadata is handled elsewhere in the codebase for consistency.

Repro

Su un arke_system già seedato (cioè il percorso normale a runtime con progetto avviato):

QueryManager.create(:arke_system, ArkeManager.get(:arke_project, :arke_system),
  id: "repro_project", label: "repro", type: "postgres_schema")

# atteso: {:ok, %Arke.Core.Unit{}} e lo schema esiste
# ottenuto: {:error, [%{message: "cannot create project schema"}]}

@vittorio-reinaudo
vittorio-reinaudo requested a review from a team as a code owner August 14, 2026 16:16
@ilyichv

ilyichv commented Aug 14, 2026

Copy link
Copy Markdown
Member

Please add tests

ErikFerrari pushed a commit to arkemis/arke that referenced this pull request Aug 28, 2026
## Description

Metadata reloaded from jsonb comes back with string keys, so the
`:transaction` opt-out on arke_project is never read after boot and
project creation fails with "cannot create project schema".

This makes atom keys the canonical metadata shape, enforced once in
`Unit.new/9` where every load path converges. Strings convert via
`String.to_existing_atom` (unknown keys stay strings), normalization is
shallow, and on a stale string duplicate the atom entry wins.

`Unit.update` normalizes data keys the same way, so a string-keyed
parameter arg updates the parameter instead of storing a stray key.

Breaking for consumers that read `unit.metadata` with string keys after
a load: those keys are now atoms when a matching atom exists.

Supersedes arkemis/arke-postgres#77, which patched only the boot-time
parse in the postgres adapter.

## Related Issue

Supersedes arkemis/arke-postgres#77

## Docs
- [ ] I have updated the docs accordingly

## Test

- [x] I have added tests that prove my fix is effective or that my
feature works
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.

2 participants