#4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used)
50 · by Luc Saffre · in Developers · assigned to Sharif Mehedi
Summary
Children
Comments
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : Yes, I committed this "cleaner" way. And (after a second commit) now also the welfare test suite is passing.
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : This made me realize that there is maybe a "cleaner" way to do it in add_voucher_item() than what Sharif had found.
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : It's the same Django error message, but the solution is different: In Django 4.1. we need to return an empty queryset when pk of the master is None. I don't know what Django <4 did in these cases (I guess it did the same...).
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : Fixed in XL, but in welfare there is a similar problem. ValueError: Problem installing fixture '...lino_welfare/modlib/welfare/fixtures/demo.py': 'Client' instance needs to have a primary key value before this relationship can be used.
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : Sharif, you didn't yet commit this, did you? I now made it locally and am testing it as well.
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : That sounds very reasonable. Well done!
- 4 years, 2 months ago by Sharif Mehedi about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : the difference in django-4.1 is that, a related manager (attribute) on an unsaved Model instance is not available.
- 4 years, 2 months ago by Sharif Mehedi about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : The following substitution in lino_xl/lib/ledger/models.py#L804 works well: # return self.items.model(**kw) return self.__class__.items.field.model(**kw)
- 4 years, 2 months ago by Sharif Mehedi about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : django says [url docs.djangoproject.com/en/4.1/releases/4.1/#miscellaneous here] that they now caches relations on Model. I am not sure but I gather that they were doing the opposite before. Which is why the relation.model is not available now, there are probably some other kind of hook, I will have...
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : Forgot to talk about this. This might actually be urgent. Please have a look at it. If it has to do with the Django version, the Django release notes might give a hint.
- 4 years, 2 months ago by Luc Saffre about #4621 ('VatProductInvoice' instance needs to have a primary key value before this relationship can be used) : For example pm prep in roger demo project says this. I guess that this is a side effect of the Django update. Full error message: ValueError: Problem installing fixture '/home/luc/work/xl/lino_xl/lib/invoicing/fixtures/demo_bookings.py': 'VatProductInvoice' instance needs to have a primary key value...