coleifer/flask-peewee — Issue #14: overridden user tablename (to users) in model's meta not honored by flask_peewee
Author: davidthewatson
Created: 2011-12-20 19:38:05+00:00
State: open

I have the following in my model, as you suggested in the bug I reported about registering a user table as per the docs in peewee with postgresql.

class User(db.Model, BaseUser):
username = CharField(unique=True)
password = CharField()
email = CharField()
join_date = DateTimeField(default=datetime.datetime.now)
active = BooleanField(default=True)
admin = BooleanField(default=False)

def __unicode__(self):
return self.username

class Meta:
db_table = 'users' # Postgres reserves user as a keyword

But flask_peewee does not honor the change, in this case I'm running against mysql:

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1518, in __call__

return self.wsgi_app(environ, start_response)

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app

response = self.make_response(self.handle_exception(e))

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app

response = self.full_dispatch_request()

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request

rv = self.handle_user_exception(e)

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1260, in full_dispatch_request

rv = self.preprocess_request()

File "/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py", line 1387, in preprocess_request

rv = func()

File "/home/watson/mine/env/lib/python2.7/site-packages/flask_peewee/auth.py", line 187, in load_user

g.user = self.get_logged_in_user()

File "/home/watson/mine/env/lib/python2.7/site-packages/flask_peewee/auth.py", line 144, in get_logged_in_user

return self.User.select().where(active=True).get(id=session.get('user_pk'))

File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 978, in get

obj = self.where(*args, **kwargs).paginate(1, 1).execute().next()

File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 1082, in execute

self._qr = QueryResultWrapper(self.model, self.raw_execute())

File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 825, in raw_execute

return self.database.execute(query, params, self.requires_commit)

File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 252, in execute

res = cursor.execute(sql, params or ())

File "/home/watson/mine/env/lib/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute

self.errorhandler(self, exc, value)

File "/home/watson/mine/env/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler

raise errorclass, errorvalue

ProgrammingError: (1146, "Table 'mine.user' doesn't exist")

Thanks!