Skip to content

Document raw column writes as the user's responsibility - #82

Merged
igor-alexandrov merged 1 commit into
masterfrom
document-raw-writes
Aug 18, 2026
Merged

Document raw column writes as the user's responsibility#82
igor-alexandrov merged 1 commit into
masterfrom
document-raw-writes

Conversation

@igor-alexandrov

Copy link
Copy Markdown
Collaborator

Settles #36 — "Should tags be de-duplicated?" — by declaring the existing split the contract. Closes #36.

The decision

The question answered itself along the write path years ago; nobody recorded it:

write what happens
song.tag_list = ["github", "github"] parser runs → TagList is a Set → stores ["github"]
song.tags = ["github", "github"] plain ActiveRecord attribute write, Metka never sees it → stores ["github", "github"]

This PR makes that the documented contract: Metka owns the *_list API; the column belongs to your schema, and normalizing direct writes is your responsibility.

What's in it

  • README: a "Writing tags: tag_list= vs the raw column" section under Tag objects, including the non-obvious consequence found while verifying the issue: duplicates stored raw are counted twice by tag clouds (UNNEST aggregates raw array elements — verified live, three posts tagged only github produced [["github", 4]]).
  • Two contract tests, one per side of the split, so a future change to either half surfaces as a deliberate decision rather than drift. The raw-write test cites the issue.

No behaviour changes — this is documentation plus pins.

Verification

114 runs, 279 assertions, 0 failures, 0 errors, 0 skips

RuboCop: 57 files inspected, no offenses. mdl README.md: clean (CI lints doc changes).

Independent PR off master, no relation to #79#81.

🤖 Generated with Claude Code

Issue #36 asked whether Metka should de-duplicate tags. The answer split
along the write path years ago without anyone recording it: tag_list=
goes through the parser, whose TagList is a Set, so it de-duplicates;
assigning the array column directly is a plain ActiveRecord attribute
write that Metka never sees, so it stores exactly what it is given.

This makes the split the documented contract rather than an accident.
Metka owns the *_list API; the column belongs to the schema, and
normalizing direct writes is the caller's job. The README section also
warns about the observable consequence of ignoring that: duplicates
stored raw are counted twice by tag clouds, which aggregate the raw
array elements.

Two tests pin the contract from both sides so a future change to either
half shows up as a deliberate decision, not drift.

Closes #36

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@igor-alexandrov
igor-alexandrov merged commit 232c483 into master Aug 18, 2026
9 checks passed
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.

Should tags be de-duplicated?

1 participant