Skip to content

Copy the metadata map in Document.mutate() - #6913

Open
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:bughunt/document-mutate-metadata
Open

Copy the metadata map in Document.mutate()#6913
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:bughunt/document-mutate-metadata

Conversation

@harrisleesh

Copy link
Copy Markdown

Motivation

Document.mutate() is documented as "allowing selective modification without altering the original", but it passes the document's internal metadata map to the new builder by reference. Builder.metadata(key, value) puts directly into that map, so mutating the builder silently mutates the original document's metadata.

Changes

  • mutate() now seeds the builder with a copy of the metadata map.
  • Added a regression test asserting the original document is unchanged after mutate().metadata(...). It fails on main and passes with the fix; the full spring-ai-commons module test suite passes (237 tests).

Fixes #6910

mutate() passed the document's internal metadata map into the new
builder by reference, so builder metadata modifications altered the
original document - contradicting the documented contract of allowing
selective modification without altering the original.

Fixes spring-projects#6910

Signed-off-by: seonghun lee <harrisleesh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document.mutate() shares the metadata map with the original document

2 participants