I’m using a RawQuerySet in Django, and I need to pass it a few parameters (5).
I’m able to call the constructor using MyModel.objects.raw(SQL, params). The SQL is pretty long and not that relevant, but params is [991L, 991L, 991L, 7L, 3].
I do get a RawQuerySet in return. Hence, the call is OK.
However, my problem is that when __repr__ is called (through print here), I get a "Not enough arguments for format string" error. Now, what I don’t get is the following:
- Why would I not have enough arguments since the call worked?
[m.start() for m in re.finditer('%s', qs.raw_query)]gives me 5 items and so doesqs.params.
I’m pretty sure I’m missing something, but I can’t seem to find what.
I eventually found the explanation. I’m not sure this will be of much help to others, but anyways.
The problem came from the fact that
paramsin the call was alist.It appears you can use alistto instantiate aRawQuerySet, but it is not converted into a tuple so you can’t use it for string-formatting later on.Conclusion I’ll use
MyModel.objects.raw(SQL, tuple(params)).