coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.2k stars 1.37k forks source link

Column with name 'insert' replaces Model class method 'insert' #1983

Closed wspek closed 5 years ago

wspek commented 5 years ago

Version: 3.9.6

I have discovered that when I create a Model which has a column literally named insert, the peewee code will throw an exception when trying to insert data through the Model.insert class method in line 6311:

pk = self.insert(**field_dict).execute()

To reproduce simply create a model which has a column named insert. In my case, after adding a Model with the column named insert, things look like this:

image

Note the type None of the insert class method, which is due to the fact that now a column exists in the model with value None. After the actual field data is added, in my case, the insert field has value False. Because the code then tries to call execute() on this boolean value, ultimately my code fails with an exception:

ERROR 'bool' object is not callable

My Model also has columns delete and create, which may cause problems by overwriting class methods with the same names. That is because I am storing a table which contains database permissions for an unrelated software solution.

Thanks.

coleifer commented 5 years ago

This is why we have stuff like "column_name":

class MyModel(Model):
    insert_ = TextField(column_name='insert')
wspek commented 5 years ago

@coleifer

I have made sure all my columns are explicitly named now by using your suggestion. I hope this GIF demonstrates well that even though the insert column has an explicit column_name set, the self.insert class method is still assuming the value of the field.

Peek 2019-08-01 13-32

wspek commented 5 years ago

Sorry, I think I get your point. I have to pay attention to the underscore you wrote down.