django-pandas icon indicating copy to clipboard operation
django-pandas copied to clipboard

read_frame bug: ForeignKey lookup fails if any Null values present

Open odoublewen opened this issue 3 years ago • 2 comments

ForeignKey lookup works as long as no null values are present. But I also have some models where null values are allowable, for example:

class Foo(models.Model):
    name = models.CharField(max_length=64, unique=True)
    description = models.CharField(max_length=128, unique=True)

    def __str__(self):
        return self.name


class Sample(models.Model):
    foo = models.ForeignKey(Foo, on_delete=models.PROTECT, null=True, blank=True)

read_frame returns expected results as long as all of the qs objects are non null for field foo:

In [25]: read_frame(Sample.objects.filter(Q(id=637)), fieldnames=['id', 'foo'])
Out[25]: 
    id          foo
0  637           XY

...but if one null is present, all rows in the df become Null.

In [26]: read_frame(Sample.objects.filter(Q(id=637)|Q(id=241)), fieldnames=['id', 'foo'])
Out[26]: 
    id          foo
0  241         None
1  637         None

Somewhat similar to #93 ?

odoublewen avatar Dec 29 '20 18:12 odoublewen