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)

manager.patch (1.0 KB ) - added by limscoder 14 years ago.
Patch to add option 'using' argument to method signature

Download all attachments as: .zip

Change History (5)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: worksforme
Status: newclosed

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.

comment:2 by limscoder, 14 years ago

Resolution: worksforme
Status: closedreopened

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)

in reply to:  2 comment:3 by limscoder, 14 years ago

Has patch: set

I attached a patch that implements the following signature: .raw(sql, params, using=default).

by limscoder, 14 years ago

Attachment: manager.patch added

Patch to add option 'using' argument to method signature

comment:4 by Russell Keith-Magee, 14 years ago

Resolution: worksforme
Status: reopenedclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top