diff --git a/piccolo/apps/asgi/commands/new.py b/piccolo/apps/asgi/commands/new.py index 746c5db9a..5c83eca0c 100644 --- a/piccolo/apps/asgi/commands/new.py +++ b/piccolo/apps/asgi/commands/new.py @@ -15,7 +15,7 @@ "fastapi": ["fastapi>=0.112.1"], "blacksheep": ["blacksheep"], "litestar": ["litestar"], - "esmerald": ["esmerald"], + "esmerald": ["esmerald==3.3.0"], "lilya": ["lilya"], } ROUTERS = list(ROUTER_DEPENDENCIES.keys()) diff --git a/piccolo/apps/migrations/auto/diffable_table.py b/piccolo/apps/migrations/auto/diffable_table.py index aa609f041..522f4f001 100644 --- a/piccolo/apps/migrations/auto/diffable_table.py +++ b/piccolo/apps/migrations/auto/diffable_table.py @@ -40,10 +40,17 @@ def compare_dicts( for key, value in dict_1.items(): dict_2_value = dict_2.get(key, ...) + if ( - dict_2_value is not ... - and dict_2_value != value - or dict_2_value is ... + # If the value is `...` then it means no value was found. + (dict_2_value is ...) + # We have to compare the types, because if we just use equality + # then 1.0 == 1 is True. + # See this issue: + # https://github.com/piccolo-orm/piccolo/issues/1071 + or (type(value) is not type(dict_2_value)) + # Finally compare the actual values. + or (dict_2_value != value) ): output[key] = value diff --git a/tests/apps/migrations/auto/integration/test_migrations.py b/tests/apps/migrations/auto/integration/test_migrations.py index 84b194ea8..0ba2901fd 100644 --- a/tests/apps/migrations/auto/integration/test_migrations.py +++ b/tests/apps/migrations/auto/integration/test_migrations.py @@ -888,6 +888,25 @@ def test_column_type_conversion_float_decimal(self): ] ) + def test_column_type_conversion_integer_float(self): + """ + Make sure conversion between ``Integer`` and ``Real`` works - related + to this bug: + + https://github.com/piccolo-orm/piccolo/issues/1071 + + """ + self._test_migrations( + table_snapshots=[ + [self.table(column)] + for column in [ + Real(default=1.0), + Integer(default=1), + Real(default=1.0), + ] + ] + ) + def test_column_type_conversion_json(self): self._test_migrations( table_snapshots=[ diff --git a/tests/apps/migrations/auto/test_diffable_table.py b/tests/apps/migrations/auto/test_diffable_table.py index 7c0cda9f3..cacd6d612 100644 --- a/tests/apps/migrations/auto/test_diffable_table.py +++ b/tests/apps/migrations/auto/test_diffable_table.py @@ -73,6 +73,19 @@ def test_enum_values(self): response = compare_dicts(dict_1, dict_2) self.assertEqual(response, {"a": OnDelete.set_default}) + def test_numeric_values(self): + """ + Make sure that if we have two numbers which are equal, but different + types, then they are identified as being different. + + https://github.com/piccolo-orm/piccolo/issues/1071 + + """ + dict_1 = {"a": 1} + dict_2 = {"a": 1.0} + response = compare_dicts(dict_1, dict_2) + self.assertEqual(response, {"a": 1}) + class TestDiffableTable(TestCase): def test_subtract(self):