Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slicing results assigns wrong values to fields #105

Open
kaselis opened this issue Dec 30, 2015 · 2 comments
Open

Slicing results assigns wrong values to fields #105

kaselis opened this issue Dec 30, 2015 · 2 comments

Comments

@kaselis
Copy link

kaselis commented Dec 30, 2015

Whenever I try to get other than the first object from DB, my object fields are shifted by one, and the last one is completely discarded. For example if I have this model:

class Person(models.Model):
    uuid = models.CharField(max_length=36, primary_key=True)
    title = models.CharField(max_length=10)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

and then if I try to fetch an object with this code

Person.objects.all()[1]

my object going to have these values assigned:

uuid = 2L
title = uuid
first_name = title
last_name = first_name

and the last_name value is discarded completely. I tracked down the issue to the generated query:

sql = "SELECT {row_num_col}, {outer} FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY {order}) as {row_num_col}, {inner}) as QQQ where {where}"

and the cause is the selection of {row_num_col} column, which is not needed for the output. It works fine for the first object, because different query is issued. I'm using django==1.8, but I don't think it matters, there is simply no reason to select that field for the output.

@kaselis
Copy link
Author

kaselis commented Dec 30, 2015

It seems there was a change in django how it converts database-python types and because of that, resolve_columns is no longer called in django 1.8:

django/django@e910340

@eskhool
Copy link

eskhool commented Jun 15, 2017

Facing the same issue...@kaselis did you find a resolution for the same?

@dlo dlo added the help wanted label Feb 1, 2018
@dlo dlo added the bug label Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants