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
Changed managers patching #32
Conversation
Hi. @Stranger6667 , If i read issue #28 correctly then the removal of objects is an intention, not a bug. However, if i do a simple model:
then it does not have For now, i'll do:
but this seems really unintuitive approach :/ or am i doing something wrong here? |
class Mymodel(models.Model):
money = MoneyField( ) For me it leads to exception during object instantiation: Mymodel.objects.create(money=Money("100.0", "USD"))
Exception: You have to provide a max_digits attribute to Money fields. |
I've added some tests for this situation |
@Stranger6667 , sorry, i was trying to be quick with this snippet so i ommited max_digits and decimal_places.. :( but the bug persist nevertherless |
Can you add some code, please? to make it clear for me :) |
@Stranger6667 Here's the core excerpt:
and the error in question:
However, when i just add the objects manager, everything works as expected.
i believe (but this is just a long shot) that the problem may lie here: https://github.com/jakewins/django-money/blob/master/djmoney/models/fields.py#L173
So if there is no 'objects' attribute, the following if statement will be ommited, leaving the class without even the most basic objects manager. I believe previously it was something like this:
which caused the manager to be assigned regardless of whether it was there or not. best regards ;) |
This is the cause, right? |
I think all this situation was caused by wrong choice of place of managers initialization. Let me explain myself. |
Thanks, @Stranger6667 for explaining. I think there was an issue somewhere about multiple MoneyFields on the same Model not working -- so that might be an explanation, too. We could optimize it a bit by, say, not looping through the fields of the model, but simply looking for some if getattr(sender._meta, '_has_money_field', False):
for _id, name, manager in sender._meta.concrete_managers:
setattr(sender, name, money_manager(manager)) |
Seems very reasonable :) but it would be better with |
Well alright then :) |
@benjaoming This code has a potential problem when model uses two or more managers. This code overwrites every manager to e.g. If model has
|
@inureyes that sounds reasonable, not sure if it's supposed to be so. Current code |
@benjaoming Ok. I'll make a quick fix for that. |
I think we should cover this migration issue in tests. I can add them later, thank you for the report :) |
I propose a solution to the problem, which I mentioned here #28.
It's based on class_prepared signal usage.