Forums

Django + Spatialite broken after upgrading from 14.04 to 16.04

Hi there,

On my new account, I cannot seem to get the Django's geographic framework working with sqlite3 and Spatialite.

I have a relatively old account (alexmorozov) running Ubuntu 14.04 with sqlite 3.8.2. My Django installation works just fine.

I opened another account and tried to transfer the application from my old one. The new account has Ubuntu 16.04 and sqlite 3.11.0, presumably compiled without dynamic extension support. This causes Spatialite to fail with a message:

ImproperlyConfigured: SpatiaLite requires SQLite to be configured to allow extension loading.

My guess is that sqlite3 may need to be recompiled or reconfigured to allow dynamic extensions, otherwise GeoDjango will be non-functional on all the new accounts.

Is there a chance to reconfigure sqlite3 to support GeoDjango?

Hmmm, we haven't changed how we install SQLite3 -- in both the 14.04 image and the 16.04 one, we just use apt-get install to install the libsqlite3-dev and sqlite3 packages, plus (or course) their transitive dependencies.

It certainly looks like the sqlite3_load_extension function is available:

$ nm -D /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 | grep sqlite3_load_extension
000000000004c050 T sqlite3_load_extension

Have you changed the Python version you're using in the new account? I get the impression that there have been changes over time to how extension loading has worked.

Giles, thanks for the prompt response and I appreciate your help. You are absolutely correct, I was too hasty to blame the sqlite3 binary.

After a bit of research, I found a footnote in Python docs. It looks like Python is now compiled without the dynamic extension support and in order to enable it one has to recompile Python itself. The only thing I cannot understand is how did it work before. I am using 3.6 for both accounts and Django version is pinned. Weird.

Any chance to get the –enable-loadable-sqlite-extensions feature enabled in PythonAnywhere's Python binaries?

We can certainly schedule that, but it would require a new system image, which will take a while -- perhaps even months -- to roll out.

Two possibilities for the meantime -- I think that if you use Python 3.5, it will have that flag enabled even in the most recent system image (we install it differently to 3.6 and 3.7). If that doesn't work, we could switch your new account over to the same system image as the old account -- just let us know if you'd like us to do that.

Giles, thanks for the explanation. I have tried the 3.5 option, and it doesn't seem to work. Is it possible then to switch the account ysm to the image that runs alexmorozov? That would be very helpful!

Sure! Could you post here as ysm requesting that, though, just so that I can be sure that you really are the same person? (This is one of those cases where I'm 99.999% sure it's all OK, but need to follow security procedures so that I won't be caught out the one time a really clever hacker really does manage to trick me :-)

Absolutely. I hereby request switching my OS image to that of the alexmorozov account. :p

Thanks for confirming! That's done. Any new consoles you start will use the new system image; websites and tasks will pick it up the next time they are restarted.

Thanks for putting the old image in, everything works like a charm now!

Excellent -- thanks for confirming!

I am having the same problem. Is there anyway I can have the change made to my account too?

Sure. That's done.

Just a quick note to say that you no longer need to use an older system image to get this to work -- our latest system image, fishnchips, has the SQL extensions flag set for all versions of Python, including 3.6, 3.7 and the new 3.8. If you would like us to switch your account over to fishnchips, please send a request through feedback while you're logged in to your account.