Hi all,

I am developing an application which needs to write an audit log to a 
database. I want the committing of log records to be independent of the 
committing of other database writes (so user actions can be audited even if 
they cause errors). So I figured the easiest way to do so would be to use the 
new multiple-database support: The logging would go on a separate connection, 
and I can then commit it separately.

The twist is, I don't want the log to go to a separate database -- just to a 
separate connection. So I use two aliases with the same parameters. And 
testing misbehaves.

At first, I did it with a trivial

DATABASES['auditlog'] = DATABASES['default']

in the settings, and with no explicit TEST_NAME for the database. Assume my 
database is named "main"

Now, when I tried to run tests, the tests refuse to run unless the "main" 
(i.e. non-test) database exists. While running, the test creates databases 
"test_main" and "test_test_main"; when it ends, it removes "test_test_main" 
and "main", so that only "test_main" remains. This is quite nasty. I can guess 
where it comes from (the DATABASES values are manipulated for testing, and 
nobody thought there could be two references to the same dict there), but 
anyway, seems buggy.

Things get better if I either separate the dicts by

DATABASES['auditlog'] = DATABASES['default'].copy()

or explicitly specify the TEST_NAME in the definition; then I still get 
misbehavior (the harness tries to create the database twice and fails to 
destroy it the second time), but that's an "acceptable" misbehavior.

I anticipate that there will be some "that's not the way to achieve what you 
want" responses, and I welcome any suggestions to achieve the same goal 
otherwise, but even if what I am doing is considered utter misconfiguration, I 
think it should be handled a little more gracefully than deleting the main 
database -- please consider this before sending me off to django-users.

Barring any glaring omission on my part, I'd like to open a bug for this.

Thanks,
        Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to