Open NikolayCherniy opened 3 years ago
Not sure I understand the issue. If the model does not have a "pk" field, it's expected that match_field should fail if you use the default. Just specify the one you want. Or have I misunderstood the report?
I think it would be more clear if the default value will be "id", cause every model has field "id" from the stock, and doesn't have field "pk". Or pk field name should be got through "_meta.pk.attname" method or replaced with "_get_pk_val"
I was under the impression it would be otherwise actually. The default primary key is usually “id” but “pk” would always translate to the actual one (even if primary key was manually set on another model)
I’ll add a test for this and update accordingly
It works only with model attribute "pk" for example
User = get_user_model()
User.objects.create(...)
User.objects.first().pk
works as you expect, but for get_field that doesn't work:
User._meta.get_field("pk")
django.core.exceptions.FieldDoesNotExist: User has no field named 'pk'
Get exception FieldDoesNotExist when match_field is not specified. match_field='pk' match_field = (match_field,) if isinstance(match_field, str) else match_field _match_fields = [self.model._meta.get_field(name) for name in match_field]
Easy way to reproduce from django.contrib.auth import get_user_model User = get_user_model() User._meta.get_field("pk") django.core.exceptions.FieldDoesNotExist: User has no field named 'pk'
Django==3.2.8 django-bulk-update-or-create==0.3.0