Improve default= handling on MoneyField - #60
Conversation
Codecov Report
@@ Coverage Diff @@
## master #60 +/- ##
=======================================
Coverage 96.15% 96.15%
=======================================
Files 4 4
Lines 104 104
Branches 10 10
=======================================
Hits 100 100
Misses 2 2
Partials 2 2Continue to review full report at Codecov.
|
|
Does that mean that we accept integers/strings as default values? Won't that cause even more problems? |
|
I don't think it would cause errors. Still, our API's shouldn't cause raising eyebrows, and seeing how money becomes string in migration may be causing such eyebrow raise. So I've replaced this with just returning |
|
What would call |
|
@patrys the path here is roughly |
This PR improves our handling for scenario when
MoneyField.defaultis of typeMoney:MoneyField.__init__validates thatMoney.currencyis same as one passed in thecurrencyargument, and raisesValueErrorotherwise, so its impossible to create model with field as such:MoneyField.deconstructtests if default value is instance ofMoney, and if that is the case, deconstructskwargs['default']tostr(Money.amount), so migrations generated by Django don't importpricesand don't construct explicitMoney, which should make them more future-proof.If somebody out there already has model like in our
InvalidModelchange, this will be breaking change for his/her project.