Issue: AttributeError: 'bool' object has no attribute 'name' while getting self._pk value.
Author: lalit-lintel
State: closed
Created: 2019-06-20 12:32:41

I am using a model without a primary.  and also used peewee signals

To have a model without a primary key, I declare it like below.

```python
class MyModel(base.BaseModel):
    field1 = pw.IntegerField(index=True)
    field2 = pw.IntegerField()

    class Meta:
        primary_key = False
```

But on create I am getting below error.

```python
Traceback (most recent call last):
  File "/home/lalit/app/venv/lib/python3.6/site-packages/peewee.py", line 5454, in create
    inst.save(force_insert=True)
  File "/home/lalit/app/src/myfile.py", line 23, in save
    super().save(*args, **kwargs)
  File "/home/lalit/app/venv/lib/python3.6/site-packages/playhouse/signals.py", line 68, in save
    pk_value = self._pk
  File "/home/lalit/app/venv/lib/python3.6/site-packages/peewee.py", line 5519, in get_id
    return getattr(self, self._meta.primary_key.name)
AttributeError: 'bool' object has no attribute 'name'
```

Error raised by the "save" method in Model class in signals file.


Can please look into this?

Thanks. 

I also have a similar issue when doing a `bulk_update`. Though I do have `pmid = pw.IntegerField(unique=True)` in my model.

```python
            with self.dbase.atomic():
                for idx in range(0, num_papers_update, n_batch):
                    db.PaperDB.bulk_update(self.update_l[idx:idx+n_batch],fields=[db.PaperDB.pmid,
                                                             db.PaperDB.title,
                                                             db.PaperDB.abstract,
                                                             db.PaperDB.journal,
                                                             db.PaperDB.authors,
                                                             db.PaperDB.pubdate,
                                                             db.PaperDB.mesh_terms,
                                                             db.PaperDB.publication_types,
                                                             db.PaperDB.chemical_list,
                                                             db.PaperDB.keywords,
                                                             db.PaperDB.doi,
                                                             db.PaperDB.delete,
                                                             db.PaperDB.affiliations,
                                                             db.PaperDB.pmc,
                                                             db.PaperDB.other_id,
                                                             db.PaperDB.medline_ta,
                                                             db.PaperDB.nlm_unique_id,
                                                             db.PaperDB.issn_linking,
                                                             db.PaperDB.country,
                                                             db.PaperDB.pubyear,
                                                             db.PaperDB.pubmonth,
                                                             db.PaperDB.pubday])
```
```bash
~/anaconda3/lib/python3.8/site-packages/peewee.py in bulk_update(cls, model_list, fields, batch_size)
   6350 
   6351         for batch in batches:
-> 6352             id_list = [model._pk for model in batch]
   6353             update = {}
   6354             for field, attr in zip(fields, attrs):

~/anaconda3/lib/python3.8/site-packages/peewee.py in <listcomp>(.0)
   6350 
   6351         for batch in batches:
-> 6352             id_list = [model._pk for model in batch]
   6353             update = {}
   6354             for field, attr in zip(fields, attrs):

AttributeError: 'dict' object has no attribute '_pk'

```

Additionally is there a way to not need to define all the fields repeatedly here and just update all fields with the incoming fields? Or could bulk_update just update the relevant ones in the list item that are being fed in?

http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.bulk_update - you have to pass list of model instances to `bulk_update()`.