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

field_cast_sql doesn't work if default database isn't MSSQL #85

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As raised in Issue 72, if the default database isn't MSSQL then a call to 
django.db.connection is going to cause an error when determining SQL Server 
version.

Because DatabaseOperations does not store the db alias anywhere, when 
field_cast_sql is called, it references self.sql_server_ver *without* sending 
in a value for connection.

This will cause an error.

I may be incorrect here, but I don't see any way this can be resolved without 
either:

a) Sending in the connection when calling field_cast_sql OR
b) Sending in the connection alias when creating the DatabaseOperations object

My patch (included in issue #72) resolved it using option b. The patch is here:
http://code.google.com/p/django-pyodbc/issues/attachmentText?id=72&aid=-86646640
63618338815&name=connectiondiff.patch&token=4427a5a8e6880b18f46185a0a08db1ee
As you can see, self.ops is initialized with the value from self.alias defined 
in DatabaseWrapper.

Can someone please come up with a more elegant solution to this? This is a hard 
error. Unless I'm missing something, the code in its current state will 
*always* break on any config where the default database isn't MSSQL.

For the time being I'm not using the current version and using my (admittedly 
messy) patch.

Original issue reported on code.google.com by jordanth...@gmail.com on 5 Jul 2010 at 3:08

GoogleCodeExporter commented 9 years ago
duplicate of #81 which now has a patch.

Original comment by hgee...@gmail.com on 1 Nov 2010 at 12:47