Issue: chaining where clauses fails
Author: fredrikchabot
State: closed
Created: 2020-03-29 12:50:49

peewee 3.13.1
pypy 7.3.0

With debugging on:

>>> len(list(Plrgl().select().where(Plrgl.pln==14578)))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE ("t1"."pln" = %s)', [14578])
2
>>> len(list(Plrgl().select().where(Plrgl.pln==14578).where(Plrgl.rgl==2)))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE %s', [False])
0
>>> len(list(Plrgl().select().where(Plrgl.pln==14578))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE %s', [False])
0

And **any** query after that fails.





There's something wrong with your code/models. Maybe you're using properties or something else? I've added a regression test which shows where-clause chaining works fine:

9cc0d09c5810d02681ddc68097291e7005a8d13a

Running the same queries in cPython work.

Nothing special in the model.

class Plrgl(BaseModel):
    pln = ForeignKeyField(Plkop, db_column='pln', backref='plrgl')
    rgl = IntegerField()
    snr = IntegerField()
    niv = ForeignKeyField(Plwst, db_column='niv', backref='plrgl')

    ste = IntegerField(null=True)
    afd = ForeignKeyField(Dsafd, db_column='afd', backref='plrgl')
    dss = IntegerField(null=True)
    oms = CharField(null=True)
    std = CharField(null=True)
    end = CharField(null=True)
    frq = IntegerField(null=True)
    frs = IntegerField(null=True)
    wma = CharField(null=True)
    wdi = CharField(null=True)
    wwo = CharField(null=True)
    wdo = CharField(null=True)
    wvr = CharField(null=True)
    wza = CharField(null=True)
    wzo = CharField(null=True)
    mns = IntegerField(null=True)
    tyd = IntegerField(null=True)
    vla = IntegerField(null=True)
    vlb = IntegerField(null=True)
    vlc = IntegerField(null=True)
    vld = IntegerField(null=True)
    vle = IntegerField(null=True)
    f6lock = IntegerField(null=True)
    recordid = BigIntegerField(unique=True)

    class Meta:
        table_name = 'plrgl'
        indexes = (
            (('niv', 'pln', 'rgl', 'snr'), True),
            (('pln', 'dss', 'afd', 'niv', 'snr', 'rgl'), True),
            (('pln', 'niv', 'snr', 'rgl'), True),
            (('pln', 'rgl', 'snr', 'niv'), True),
            (('rgl', 'niv', 'snr', 'pln'), True),
            (('rgl', 'pln', 'ste', 'niv', 'snr'), True),
        )
        primary_key = CompositeKey('niv', 'pln', 'rgl', 'snr')



> the same queries in cPython work.

Then I guess it's a bug in pypy.