﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32231	It should be possible to pass None as params for Model.objects.raw	Alexander Lyabah	Alexander Lyabah	"I was playing with:

* psycopg2==2.8.6
* last django 2.2 (-e git+git@github.com:django/django.git@e893c0ad8b0b5b0a1e5be3345c287044868effc4#egg=Django)

Model.objects.raw has raw_query and params=None attributes, as well as cursor.execute has the same attributes, and `raw` will eventually calls `execute`, since `raw` is more low-level way of using DB.

But, params=None of `raw` function doesn't pass as None into `execute` function, but empty tuple instead.

The problem here is that, psycopg2 treats differently params=None and params=(), and it is impossible to pass None using `raw` function.

The simple example can be found in test from patch

        query = ""SELECT * FROM raw_query_author WHERE first_name like 'J%'""
        qset = Author.objects.raw(query)
        results = list(qset)
        print(len(results))

in current Django version (I was using 2.2) it raises an exception from psycopg2

The attached patch allows using None in params
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	raw, psycopg2, execute, orm, db		Ready for checkin	1	0	0	0	0	0
