0

I have this table in mysql,

import peewee

class User(peewee.Model):

    username = peewee.Charfield(max_length=60)
    email = peewee.Charfield(max_length=300)

    def __repr__(self):
        return "<User: {}>".format(self.username)

when I try the below code for an existing user:

User.get(email="zhaochang@qq.com")

it returns <User: zhaochang>

but for a random email/user that dose not exists User.get(email="some_random@email.com") it throws error:

UserDoesNotExist: Instance matching query does not exist:

SQL: SELECT 't1'.'id', 't1'.'email', 't1'.'username' FROM 'user' AS t1 WHERE ('t1'.'email' = %s) PARAMS: [u'some_random@email.com']

I was expecting for User.get method to return None.

Chang Zhao
  • 631
  • 2
  • 8
  • 24

1 Answers1

1

Why would you expect the method to return None when the documentation clearly states that

If no model is returned, a DoesNotExist is raised.

Source: http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get

BoboDarph
  • 2,751
  • 1
  • 10
  • 15