Django update_or_create within a loop is duplicating field values, but just a couple fields

It's been a while but I have a somewhat puzzling issue. I am looping over some data being pulled from an api and performing an update_or_create call through django.

for product in response['products']:
    for variant in product['variants']:
        obj, created = Product.objects.update_or_create(
                'name': product['title'],
                'price': variant['price'],
                'sku': variant['sku'],
                'shopify_product_id': variant['product_id'],
                'shopify_variant_id': variant['id'],
                'weight_grams': variant['grams'],

During the loop you'll notice I am printing the value of the variant product id.


In the console I see the print results are correct with different variant product ids.


But in the database both the variant['product_id'] and variant['id'] are all the same for every row. Yet the other details such as name and price are all correct and differ per row.

enter image description here

I can not for the life of me figure out why this is happening. I am using the sku as the unique identifier to filter on and it is set as unique in my model. No matter what I do or try, it is only those two fields that get duplicated.

Well, I am embarrassed to say I figured it out. I had the model fields set to integer and the integers that are used for the two IDs were larger than the integer field can handle. I switched them to big integer fields and now all is well!

Back to Top