Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta_options are overwritten by clauses in child-classes #392

Closed
alexlatchford opened this issue Jul 15, 2014 · 1 comment
Closed

meta_options are overwritten by clauses in child-classes #392

alexlatchford opened this issue Jul 15, 2014 · 1 comment

Comments

@alexlatchford
Copy link
Contributor

Hi Charles,

I think this example should be valid but is having difficulties:

from peewee import *

db = SqliteDatabase(':memory:')
db.connect()

class BaseModel(Model):
    created = DateTimeField()

    class Meta:
        database = db
        order_by = ('-created',)

class Extension(BaseModel):
    some_field = CharField()

Gives the following error:

alexs-air:Code alexlatchford$ python test.py 
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    class Extension(BaseModel):
  File "/Library/Python/2.7/site-packages/peewee.py", line 2990, in __new__
    cls._meta.prepared()
  File "/Library/Python/2.7/site-packages/peewee.py", line 2861, in prepared
    field = self.fields[clause.lstrip('-')]
AttributeError: 'DateTimeField' object has no attribute 'lstrip'

Sorry I haven't had time to investigate it and find a patch, I'll see what I can do if this really annoys me. I'm just putting the order_by declarations on the sub-classes instead of the parent :)

Thanks,
Alex

@coleifer
Copy link
Owner

Thanks for reporting this -- yes, peewee replaces the order_by string with a clause, but this is acting up in the chlid-classes. I will get a fix out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants