- Notifications
You must be signed in to change notification settings - Fork590
Update database.py#104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Don't write db if _default is an empty Table.If there are no documents in the _default table, TinyDB will write (and thus, re-serialize) the entire database.This is because bool({}) == False, although the table does exist.This time, don't break the tests.
KeksKeksKeks commentedJun 13, 2016
Classical case of RTFM :( I should have read the contribution instructions first. I have added a test to demonstrate the original behaviour, introduced changes to make it go away, and added the neccessary changes to make the coverage check happy. Kudos for such a thorough code infrastructure! I enjoyed using (and now, contributing to) TinyDB. |
msiemens commentedJun 14, 2016
That makes sense, thank you! Just out of curiosity: I find it interesting that the VCS tracks the file modification time. Which one are you using? |
KeksKeksKeks commentedJun 14, 2016
You're welcome! I use git, which doesn't track file modificationtime. Instead, because python dicts are unordered, two JSON serialisations of the same database will look different. And a different filecontent is, of course, then detected by the VCS. |
msiemens commentedJun 14, 2016
Ah, I see! Unexpected reordering of Python's dicts have bitten me more than once 😄 |
eugene-eeo commentedJun 19, 2016
Turns out there is a |
As mentioned insixty-north/cosmic-ray#171, PR#104 wasn't listedin the changelog for v3.2.1.
Don't write db if _default is an empty Table.
If there are no documents in the _default table, TinyDB will write (and thus, re-serialize) the entire database.
This is because bool({}) == False, although the table does exist.
I have a JSON file under version control, which doesn't use the default table. Recently, I noticed that the file changes although I didn't change any document within the database.
Apparently, TinyDB.init reads the default table, which is empty in my case. An empty document evaluates to False in a boolean context, and TinyDB will write a new, empty table, effectively re-serializing the database on read.