Fighting with python, sqlite3, and OperationalError: unable to open database file

I have been fighting for quite some time with sqlite3 and python because neubot -S (the command to start neubot master server) was failing to commit new results into the database. The (rather cryptic) error message at the end of the stacktrace was:

OperationalError: unable to open database file.

The interesting part was that the error was triggered by write operations only. And I was puzzled because I was sure that the process had the permission to write into /var/neubot/database.sqlite3.

I googled a bit and finally I found the answer: the sqlite3 library needs write permissions also on the directory that contains the database, probably because it needs to create a lockfile.