-
Notifications
You must be signed in to change notification settings - Fork 578
Open
Description
- Make a Python object
obj
with a nested dict - Insert it into the database
- Change a value in
obj
's nested dict - Make a query that retrieves obj
- It has your change
See below:
from tinydb import TinyDB, Query
from tinydb.storages import MemoryStorage
db = TinyDB(storage=MemoryStorage)
t = db.table("test", cache_size=0)
obj = {"a": "a", "b" : "b", "nested": {"c": "c"}}
t.insert(obj)
print("inserted", obj)
obj['nested']['c'] = "X"
obj2 = t.get(Query().a == "a")
print("retrieved", obj2)
inserted {'a': 'a', 'b': 'b', 'nested': {'c': 'c'}}
retrieved {'a': 'a', 'b': 'b', 'nested': {'c': 'X'}}
I'm guessing somewhere the nested dict is being saved as a reference, not as a copy. I've confirmed it's not the query cache by setting it to zero.
This doesn't happen with normal JSON storage.
Metadata
Metadata
Assignees
Labels
No labels