﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26555	makemigrations serializer isinstance() check fails for subclasses of Decimal (and DateTime etc)	oTree-org	Markus Holtermann	"The migrations serializer uses `isinstance(value, decimal.Decimal)` to check if a value is a decimal:

https://github.com/django/django/blob/ecb59cc6579402b68ddfd4499bf30edacf5963be/django/db/migrations/serializer.py#L363

If so, it adds `from decimal import Decimal` to the beginning of the migrations file:

https://github.com/django/django/blob/ecb59cc6579402b68ddfd4499bf30edacf5963be/django/db/migrations/serializer.py#L87

The problem with `isinstance()` is that it results in false positives for subclasses. I am using a subclass of `Decimal` called `Money` as the default value for many of my model fields (subclass of `DecimalField` called `MoneyField`), and the migrations writer adds an incorrect `from decimal import Decimal` to my migrations files, which still results in a `NameError` for `Money` when I run `migrate`.

This problem also prevents me from using the `deconstruct()` method as recommended in the documentation to serialize custom classes:

https://docs.djangoproject.com/ja/1.9/topics/migrations/#adding-a-deconstruct-method

(Because the check for `Decimal` happens before the check for `.deconstruct()`.)

I think instead of `isinstance(value, decimal.Decimal)`, the code should be `if type(value) == decimal.Decimal`.
"	Bug	closed	Migrations	dev	Normal	fixed		Markus Holtermann	Accepted	1	0	0	0	0	0
