Open jorisroovers opened 9 years ago
I have a similar issue - looking at my trace file, the DB connection from get_new_connection has a connection string of [length = 170 (SQL_NTS)], while the DB connection from _cursor is [length = 134]
I'm putting together a pull request for this now, but I'm not sure how to unittest it.
When using test fixtures in combination with FreeTDS, I keep running into the following error:
For the most part, the key to solving this issue is specifying
TDS_VERSION=8.0
as part of theextra_params
in theOPTIONS
key of Django'sDATABASES
setting.However, this problem keeps occurring when running unit tests that make use of test fixtures, even though it doesn't occur when regular users are hitting the code in question.
After spending multiple hours on this, I figured out that the django test runners call the
get_new_connection()
method of theDatabaseWrapper
class in django_pyodbc's base.py module. https://github.com/lionheart/django-pyodbc/blob/master/django_pyodbc/base.py#L182This method is not called when using regular code, instead the DB connection is created during the first call to
_cursor()
: https://github.com/lionheart/django-pyodbc/blob/master/django_pyodbc/base.py#L267I believe the issue here is that
get_new_connection()
doesn't specify the connectionstring to pyodbc as is done in_cursor()
: https://github.com/lionheart/django-pyodbc/blob/master/django_pyodbc/base.py#L278A workaround is to explicitly specify the connectionstring as follows:
However, this should be fixed in
get_new_connection()
itself. I believe the fix is as straightforward as calling_get_connection_string()
and passing it toDatabase.connect()
as its first argument. I'd be happy to submit a pull request if someone can confirm this and the repo owner is accepting fixes.