google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Problem with multi-db if pyodbc is not the default connection #102

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. use Django multi-db support, create database connection using django-odbc 
which is not default and have the default one use different database driver 
(SQLite3, MySQL, ...)
2. Query MS SQL database model using .get() (either via .using() or database 
router)
3. Observe the error message

The problem is that there are 2 instances of using default database connection 
in operations.py (to get database connection cursor). The cursor is created on 
default, non-MSSQL database, which creates problem.

I monkeypatched my copy of the code the following way:

original:
                from django.db import connection
                cur = connection.cursor()

my copy:
                # workaround for multi-db support if not default db
                from django.db import connections
                mssql_aliases = [x for x in connections if 'sql_server' in connections[x].settings_dict['ENGINE']]
                conn = connections[mssql_aliases[0]]  # take the first one
                cur = conn.cursor()

This is good enough for me, although it still uses the first defined MSSQL 
database connection from settings.py. I have not found a smarter way to do it 
though.

Original issue reported on code.google.com by jirka.ve...@gmail.com on 2 Mar 2011 at 3:12

GoogleCodeExporter commented 9 years ago

Original comment by vcc.ch...@gmail.com on 24 Mar 2011 at 4:55

GoogleCodeExporter commented 9 years ago
I am perplexed why the fix that I initially suggested when this issue came up 
over a year ago has still not been adopted. Instead, "fixes" which do not fix 
the issue have been applied to the code. See Issue 72

Original comment by jordanth...@gmail.com on 12 Apr 2011 at 8:45

GoogleCodeExporter commented 9 years ago
please check again with r186.

Original comment by vcc.ch...@gmail.com on 17 Apr 2011 at 4:36