pwtail / vinyl_v1

2 stars 1 forks source link

pk missing during record creation #4

Open dejmail opened 2 years ago

dejmail commented 2 years ago

Hi there, me again. I'm getting the following error when trying to create a record on the DB.The pk is normally assigned when the record is committed/saved, so I'm not really sure what is going on here. The command causing the problem is called as follows

await TableUpdateDate.vinyl.create(
            company = company,
            datatable=table,
            date=datetime.now()
        )

and a little bit later I get the following error.

    await obj.insert(using=self.db)
  File "/venv/lib/python3.10/site-packages/vinyl/saving.py", line 51, in insert
    self._prepare_related_fields_for_save(operation_name="save")
  File "/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1095, in _prepare_related_fields_for_save
    if obj.pk is None:
AttributeError: 'coroutine' object has no attribute 'pk'
sys:1: RuntimeWarning: coroutine 'VinylQuerySet.get_or_none' was never awaited

Ideas ?

pwtail commented 2 years ago

You can comment out the line with _prepare_related_fields_for_save so that it wouldn't deal with related objects

pwtail commented 2 years ago

@dejmail this looks like a bug, if you somehow let me know what your models are I may fix it