Discovered PostgreSQL Issues

Contenttypes

The fix I mentioned for the contenttypes_tests failures in my last post is a bit of a hack to me, but I think it’s the only solution that makes sense at the moment. To ensure I’m not writing terrible code, I asked one of my mentors to review it and I hope to hear from him soon to improve that test.

PostgreSQL initial problems

Running the full test suite with PostgreSQL gave a myriad of errors, can't adapt to dict. Googling it showed a steady stream of developer reports over this random error and Tim Graham showing them relevant Django documentation that instructs developers to add 'django.contrib.postgres' to their installed applications to fix this error. I added modify_settings decorators to all of the errors that were raised and that fixed it.

I think a cleaner solution would be to subclass PostgreSQLTestCase and PostgreSQLSimpleTestCase, decorate them with modify_settings(INSTALLED_APPS=['append': 'django.contrib.postgres']), and use them wherever they need to be used. This is also a better exposed API for developer usage. I’ll change that later when I’m merging it.

Two other PostgreSQL failures stood out: m2m_through and inspectdb. I worked on the latter first since it was a management command, and with my track record being 1-0 against management commands, I thought I had a better chance against it than m2m_through. Tracing through the command call made it apparent that it was an error on Windows, and after mentioning such on the GitHub PR, Nick Pope explained to me what the problem exactly was and its solution. I submitted a quick patch for that.

Moving on to the m2m_through failure, it seems to be something about the ORM itself since the test only uses a QuerySet, so I doubt it’s something related to spawned processes causing a problem. I think it’ll amount to a Windows-specific error once again like inspectdb, but I need to test it more before I can make that call.

Other minor fixes:

I made a small mistake of making the previous serialized_contents fix SQLite-specific, so I generalized it to all connections.

I rewrote a small bit of logic under the build_suite method to make it more efficient and to fix a bug. The old version would create a parallel suite using the runner’s current self.parallel attribute, then it would validate the number of parallel processes after. This caused errors on my machine. I instead rewrote it to first determine the number of parallel processes required, then initialize the parallel suite with them.