Hi Django developers,
I have been using the development copy of django from the svn trunk. I
think I may have found an area that needs updating now that django
supports multiple databases. I am not very familiar with the django
backend architecture so I am not sure if its a real bug or not and if
so how best to fix it. I would appreciate any input.
At the moment the file django/db/models/options.py has a method
contribute_to_class that is defined as:
def contribute_to_class(self, cls, name):
from django.db import connection
The imported connection is never used in the method, however if it
were used the code would be assuming that the model that is being
contributed to uses the default database. Perhaps that import should
be removed to avoid the temptation to use it and therefore force
developers to think about how to get a connection if one is needed.
Alternatively it could be changed to import the "connections"
dictionary and the "router" object. Something like:
def contribute_to_class(self, cls, name):
from django.db import connections, router
… code that initializes cls but does not need a connection …
db_name = router.db_for_read(cls)
connection = connections[db_name]
… code the needs a connection …
The reason I noticed this in the first place is because I applied the
patch that is part of ticket #6148 (
http://code.djangoproject.com/
ticket/6148) to the latest trunk code and then defined two databases,
the default to hold the standard django tables in a local sqllite3
database and one to hold my legacy data on a db2 database with
multiple schemas. I noticed that my schema information was being
dropped from models defined as part of the db2 database. The reason
was that the patch code added to contribute_to_class that used the
connection was using the default database connection and not the db2
connection. As a result, since the patched sqllite instance does not
support schema's it was being dropped from my model's _meta data.
Applying the change described here solved the problem for this ticket.
This could conceivably be considered a bug in the patch for ticket
#6148, but I thought I would raise it here to see if anyone thought it
was something that should be fixed in the original source.
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to
django-d...@googlegroups.com.
To unsubscribe from this group, send email to
django-develop...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.