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 16550 Django should load custom SQL when testing elver.loho@… nobody "When running ""python manage.py test appname"", Django fails to load the custom SQL from the appname/sql folder. I am currently forced to use the following ugly workaround: {{{ #!div style=""font-size: 80%"" Workaround: {{{#!python def load_sql(sender, connection, *args, **kwargs): if connection.settings_dict[""NAME""] != ""test_projectname"": return f = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), ""sql"", ""custom_types.sql""), ""r"") sql = f.read() cursor = connection.cursor() cursor.execute(sql) transaction.commit_unless_managed() backends.signals.connection_created.connect(load_sql) }}} }}} It is important to load the custom SQL, because I am using it to define composite objects in the Postgres backend and I have written Django wrappers for them, which work fine. These composite objects allow me to store information like ""50 USD per ton"" or ""100 EUR per kg"" in a single field. The SQL that's being loaded also defines a set of new operators, which allow me to sort based on this field on the server side, using the latest currency exchange rates and weight unit conversions. Previously I had to store this information in several standard fields and either write a complex query or load them all into Python and sort there. Please fix this." New feature closed Database layer (models, ORM) 1.4 Normal wontfix Danilo Bargen Unreviewed 0 0 0 0 1 0