Opened 14 years ago
Closed 14 years ago
#13805 closed (worksforme)
Unable to use .raw() in multi-db environment
Reported by: | liangent | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a model M
. M.objects.raw('...')
works, but M.objects.using('dbname').raw('...')
doesn't work.
Attachments (1)
Change History (5)
comment:1 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 14 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I have the same issue with 1.2.
The code M.objects.using('dbname').raw('...') causes the error: 'QuerySet' object has no attribute 'raw'.
The 'raw' method needs some way to specify which database to use. Perhaps a signature such as: .raw(sql, params, database=default)
comment:3 by , 14 years ago
Has patch: | set |
---|
I attached a patch that implements the following signature: .raw(sql, params, using=default).
by , 14 years ago
Attachment: | manager.patch added |
---|
Patch to add option 'using' argument to method signature
comment:4 by , 14 years ago
Resolution: | → worksforme |
---|---|
Status: | reopened → closed |
Such an method already exists:
M.objects.db_manager('dbname').raw('...')
raw()
isn't a queryset method, it's on the manager only. This is because you can't arbitrarily stick raw() on the end of any query, because the query might be filtered or otherwise modified in a way that raw() won't interact with.
You can call using() on the end of a raw() because a raw() queryset has already locked out other filter()-type options.
It works fine for me, and I've got a test suite to back up my assertion.
If you're having difficulties using a feature, your first stop should be to ask on django-users.