python-stdnet icon indicating copy to clipboard operation
python-stdnet copied to clipboard

`unique` and/or `primary_key` have no effect on Redis

Open SamuelMarks opened this issue 11 years ago • 3 comments

Test-case

from stdnet.odm import StdModel, CharField, Router

class Bar(StdModel):
    foo = CharField(primary_key=True, unique=True)

if __name__ == '__main__':
    models = Router('redis://localhost:6379?db=1')
    models.register(Bar)

    with models.session().begin() as transaction:
        transaction.add(models.bar.new(foo="Hello world"))
        transaction.add(models.bar.new(foo="Goodbye world"))
    with models.session().begin() as transaction:
        transaction.add(models.bar.new(foo="Hello world"))
        transaction.add(models.bar.new(foo="Goodbye world"))

    for f in models.bar.query().all():
        print '%r = %s' % (f, f.foo)

Output

Bar: Bar object = Hello world
Bar: Bar object = Goodbye world
Bar: Bar object = Hello world
Bar: Bar object = Goodbye world

FYI: I am running python-stdnet 0.8.2 on Python 2.7.5+ with Redis 2.8.2 on Ubuntu. Additionally have tried with python-stdnet 0.9a3.

SamuelMarks avatar Jan 04 '14 13:01 SamuelMarks

Replace CharField with SymbolField

lsbardel avatar Jan 05 '14 09:01 lsbardel

Thanks, that fixed the problem.

Why does CharField support unique and primary_key; if neither work?

SamuelMarks avatar Jan 05 '14 10:01 SamuelMarks

It shouldn't you are right.

lsbardel avatar Jan 05 '14 10:01 lsbardel