Skip to content

Modifying documents returned by search modifies the query cache #516

@msiemens

Description

@msiemens

Discussed in #515

Originally posted by sakam0to February 23, 2023
A snippt codes

from tinydb import TinyDB, Query
db =  TinyDB("test.json")
db.insert({"id": 1})

q = Query()
records = db.search(q.id == 1)
records[0]["name"] = "N1"

db.search(q.id==1)
>>[{'id': 1, 'name': 'N1'}]
db.all()
>>[{'id': 1}]

You can see that modifications to the search function result affect the later search results. But it doesn't change the records on the disk. Is it expected or not?

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributions-welcomeHappy to accept pull requests for this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions