approach SimpleDatabase with care ... #2

Open
opened 3 years ago by mb · 1 comments
mb commented 3 years ago

@decentral1se: "watch out for that SimpleDatabase, there are some secret bugs! you always need to run _dumps() when you want to be sure to save because of an obsure behaviour in python"

@decentral1se: "watch out for that SimpleDatabase, there are some secret bugs! you always need to run _dumps() when you want to be sure to save because of an obsure behaviour in python"
Owner

An example of having some logic which always force a _dumps() call is here fa80d094a7/xbotlib.py (L559). I think if you have a db = SimpleDatabase() and then you do db['a'] = [] and then db['a'].append(1) then the .append doesn't trigger a _dumps() call. You have to do it yourself.

You can use a https://docs.python.org/3/library/shelve.html instead which won't give you issues but then you miss out how easy it is to read the local JSON file.

Hope that makes sense!

An example of having some logic which always force a `_dumps()` call is here https://git.vvvvvvaria.org/decentral1se/xbotlib/src/commit/fa80d094a7ed13b3cb210dcb227116d571326a7e/xbotlib.py#L559. I think if you have a `db = SimpleDatabase()` and then you do `db['a'] = []` and then `db['a'].append(1)` then the `.append` doesn't trigger a `_dumps()` call. You have to do it yourself. You can use a https://docs.python.org/3/library/shelve.html instead which won't give you issues but then you miss out how easy it is to read the local JSON file. Hope that makes sense!
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.