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

OperationalError while bulk updating the tortoise model. #1633

Closed
adhilabu opened this issue May 29, 2024 · 1 comment
Closed

OperationalError while bulk updating the tortoise model. #1633

adhilabu opened this issue May 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@adhilabu
Copy link

Facing OperationalError while bulk updating the product model with the below data. Here I have set basemodel_ptr_id as the primary key in the database and I have assinged basemodel_ptr_id to id in the product model.

Product Model

class ProductModel(Model):
    basemodel_ptr: ForeignKeyFieldInstance[BaseModel]  = fields.OneToOneField('models.BaseModel') 
    id = fields.IntField(unique=True, pk=True, source_field="basemodel_ptr_id")
    name = fields.CharField(max_length=200)
    no_of_items = fields.DecimalField(max_digits=20, decimal_places=2)

Error

tortoise.exceptions.OperationalError: column "id" does not exist

To Reproduce

This below line of code will replicate the issue with the above product model.

ProductModel.bulk_update(objects=prods_to_update, fields=['no_of_items'], batch_size=50, using_db=db_conn)

Expected behavior

Latest model should be updated without any error and it should identify the primary key based on the source field defined for the model in the id.

@abondar abondar added the bug Something isn't working label May 31, 2024
@abondar
Copy link
Member

abondar commented Jun 1, 2024

Fixed in 0.21.3

@abondar abondar closed this as completed Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants