[storm] django-support branch progress

James Henstridge james at jamesh.id.au
Tue Sep 2 07:46:02 BST 2008


I thought I'd post about the progress on the django-support branch is going.

When I first announced the branch, it was far enough along to write a
Django application that used Storm objects instead of Django's native
ORM.  Since then, I've been working on getting Storm to cooperate with
the Django ORM.

At first, I was hoping to provide some kind of proxying Storm models
into the Django ORM, but didn't have much luck with that.  Instead
I've been focusing on allowing you to use the two ORMs in parallel.
That is, an app can primarily use Storm while still using external
compoents that depend on the Django ORM (e.g. django.contrib.auth,
django.contrib.sessions, etc).

To facilitate this, I wrote a new Django DB backend, which can be
enabled with the following in the Django settings file:

DATABASE_ENGINE = 'storm.django.backend'
DATABASE_NAME = 'store_name'

This will cause the Django ORM to use the connection of the named
per-thread store.  At present it only supports the PostgreSQL and
MySQL Storm backends.  Calling the _commit() or _rollback() methods on
the backend call the global transaction.commit() or
transaction.abort() functions (so will be coherent with Storm's
cache).  Having the Django ORM share the same connection has a number
of benefits:

1. For a single database application, you've just got one connection
per request so don't need to worry about two phase commit (which we
don't support yet anyway).
2. Since the two ORMs are sharing the same transaction, foreign keys
from Django managed tables to/from Storm managed tables should mostly
work.

The ZopeTransactionMiddleware class has also been modified to put
Django into "managed transaction mode" similar to the existing
TransactionMiddleware class, so you won't see unexpected commits
within a request unless code uses the @commit_on_success or
@autocommit decorators.

I think the branch is now in a usable state, so the branch is now in
needs review state.

The next step in improving the code would be to write analogues of
Reference and ReferenceSet that can be used to link from one ORM to
the other.

James.



More information about the storm mailing list