Hello!

Two things, specific and more abstract:

1. I've run into something that seems like a bug. If it really is a bug, 
I'll file a ticket, if it's not, please clarify the behaviour, and, in this 
case, I think a better error message will be awesome.

Basically, if there are two permissions for a model with same codenames and 
different descriptions, Django tries to add both in the database, but there 
is a unique index on codename so it all crashes horribly.

The code which is responsible for this is at create_permissions() 
function[1]. There is a set: `searched_perms`, so it should help to avoid 
duplicate values. But the second element of every tuple in set, namely 
"perm", is another tuple of (codename, name), and the "name" is a 
human-readable name and not an identifier. So if we have two permissions 
with same codenames, but different "name"s, set will see them as different 
permissions and django will try to insert them both in the database. 
However, the unique index is only on two fields: ctype and codename, so 
permissions with same ctype and codename, but different "names", can't be 
inserted. That results in a pretty odd stacktrace[2]. Please ignore that it 
is from South, I'm pretty sure it has nothing to do with all of this mess. I 
never tried, though.

The simple case with duplicate permissions is adding a "change_thingy" 
permission to your model. Even if one forgets about this permission already 
added by Django, he doesn't deserver suffering and using pdb to understand 
what's going on :-)

So, please, let's decide if it's a bug in behavior or a bug in 
error-reporting and solve it!

2. Another idea being in my head lately is that since there is a better 
logging support in django nowadays, maybe it's time to try adding a dozen of 
warnings and suggestions to humble Django users. I'd like to try to improve 
overall error-reporting and in Django. Several ideas from the top of my 
head:

* Handling apps with no "models.py". It seems like Django silences this 
error and removes the app from the app list. It doesn't play nice with 
several things, like testing. I think there should be a warning in 
runserver's console.

* I think there should be ready to use runserver-console handler for logging 
(seems like just a normal StreamHandler), and it could be enabled by default 
in settings.py

* I also think there should be some interesting logging namespaces, like 
django.db.query for logging all queries.

* An awesome feature will be helping with solving O(n) queries errors (and 
other database mistakes) - gentle warnings in console when two almost same 
queries are running during the same request. It doesn't seem like a simple 
task to do, but definitely like an interesting one.

Sorry if some of these is already in Django or in the bug tracker.


[1]: 
http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/management/__init__.py#L19
[2]: https://gist.github.com/945736

-- 
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