That was a tricky one! If you have a complex raw SQL running in Django, you need to have a "primary key" added to the result (even if it doesn't make sense). I was selecting from a CTE, so I didn't have a primery key. Discovered that if I add `SELECT 1 AS id,` in the beggining of my query, Django is happy and everything works fine!