Issue: Setting schema in Meta class does not propagate
Author: Karel-van-de-Plassche
State: closed
Created: 2018-02-10 20:09:05

I usually set a schema in my main class, but it doesn't propagate to subclasses since `3.0.16`. This causes any select to fail because the schema is not set in the raw SQL. Probably caused by #1483, commit 5cfc311eea8adb0d8aa836f493c3f9faf615b745.

``` Python
db = PostgresqlExtDatabase(database='test', host='example.org')

class BaseModel(Model):
    """A base model that will use our Postgresql database"""
    class Meta:
        database = db 
        schema = 'develop'

class TrainScript(BaseModel):
    script = TextField()
    version = TextField()
```

3.0.15:
``` Python
In [1]: BaseModel._meta.schema
Out[1]: 'develop'

In [2]: TrainScript._meta.schema
Out[2]: 'develop'
```

3.0.16:
``` Python
In [1]: BaseModel._meta.schema
Out[1]: 'develop'

In [2]: TrainScript._meta.schema

In [3]: TrainScript.select().get()
---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)
/usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit)
   2483             try:
-> 2484                 cursor.execute(sql, params or ())
   2485             except Exception:

ProgrammingError: relation "trainscript" does not exist
LINE 1: ...ECT "t1"."id", "t1"."script", "t1"."version" FROM "trainscri...
                                                             ^


During handling of the above exception, another exception occurred:

ProgrammingError                          Traceback (most recent call last)
~/working/QLKNN-develop/NNDB/model.py in <module>()
----> 1 TrainScript.select().get()

/usr/lib/python3.6/site-packages/peewee.py in get(self)
   5454         clone._cursor_wrapper = None
   5455         try:
-> 5456             return clone.execute()[0]
   5457         except IndexError:
   5458             sql, params = clone.sql()

/usr/lib/python3.6/site-packages/peewee.py in inner(self, database, *args, **kwargs)
   1445             raise Exception('Query must be bound to a database in order '
   1446                             'to call "%s".' % method.__name__)
-> 1447         return method(self, database, *args, **kwargs)
   1448     return inner
   1449 

/usr/lib/python3.6/site-packages/peewee.py in execute(self, database)
   1516     @database_required
   1517     def execute(self, database):
-> 1518         return self._execute(database)
   1519 
   1520     def _execute(self, database):

/usr/lib/python3.6/site-packages/peewee.py in _execute(self, database)
   1670     def _execute(self, database):
   1671         if self._cursor_wrapper is None:
-> 1672             cursor = database.execute(self)
   1673             self._cursor_wrapper = self._get_cursor_wrapper(cursor)
   1674         return self._cursor_wrapper

/usr/lib/python3.6/site-packages/playhouse/postgres_ext.py in execute(self, query, commit, named_cursor, array_size, **context_options)
    424         if named_cursor:
    425             commit = __named_cursor__
--> 426         cursor = self.execute_sql(sql, params, commit=commit)
    427         if named_cursor:
    428             cursor = FetchManyCursor(cursor, array_size)

/usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit)
   2489             else:
   2490                 if commit and not self.in_transaction():
-> 2491                     self.commit()
   2492         return cursor
   2493 

/usr/lib/python3.6/site-packages/peewee.py in __exit__(self, exc_type, exc_value, traceback)
   2285             new_type = self.exceptions[exc_type.__name__]
   2286             exc_args = exc_value if PY26 else exc_value.args
-> 2287             reraise(new_type, new_type(*exc_args), traceback)
   2288 
   2289 EXCEPTIONS = {

/usr/lib/python3.6/site-packages/peewee.py in reraise(tp, value, tb)
    168     def reraise(tp, value, tb=None):
    169         if value.__traceback__ is not tb:
--> 170             raise value.with_traceback(tb)
    171         raise value
    172 

/usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit)
   2482             cursor = self.cursor(commit)
   2483             try:
-> 2484                 cursor.execute(sql, params or ())
   2485             except Exception:
   2486                 if self.autorollback and not self.in_transaction():

ProgrammingError: relation "trainscript" does not exist
LINE 1: ...ECT "t1"."id", "t1"."script", "t1"."version" FROM "trainscri...
```

Fixed and pushed new version, 3.0.17. Added more tests to hopefully prevent this (or similar regressions) from recurring.