- attached test_mssql_nulls.py
MSSQL column nullability should be explicit
The nullability of an MSSQL column for which neither NULL or NOT NULL is defined in the corresponding CREATE TABLE statement is determined using a combination of database setting and 'session' setting0. The DDL that the SA MSSQL dialect generates emits no specification of nullability for columns with 'nullable=True' set on their SA Table definition. So a table defined as nullable in its SA definition will have its nullability determined by database setting.
Attached find a test case that illustrates the current behavior and a patch to make the MSSQLSchemaGenerator explicitly emit nullability specifications in all cases.
0 http://msdn.microsoft.com/en-us/library/aa259217(SQL.80).aspx
Comments (8)
-
Account Deleted -
Account Deleted - attached specify_nullablility.diff
a patch to make the desired change
-
Changed in f9b8641269b17a5f29ed58df46286f881d82035f
-
Account Deleted - removed status
- changed status to open
(original author: ram) This breaks test/sql/testtypes.py:testcolums.
The default Column() constructor in lib/sqlalchemy/schema.py does this:
self.nullable = kwargs.pop('nullable', not self.primary_key)
which sets the columns 'nullable' attribute to False for an unspecified keyword, not None.
-
repo owner I would change the tests in testcolumns to check for "mssql" and add in the "NULL" keyword in that case, there are already some db-specfic checks in that test. the default for nullable is True unless its a primary key. The functionality we're going for is that the MSSQL dialect positively asserts that the "nullable" setting is propagated to the DDL.
-
The way I've approached this elsewhere was to actually do the opposite. Explicitly add nullable=None for the mssql dialect so the results are the same. In other words remove nullability from the equation for MSSQL. Either way is fine for me and I don't think one approach or the other makes a difference for what is being tested.
-
- changed status to resolved
Corrected in 0dc8bce4fedb7359dde6ec9cdf0e98e5ed4dd0d8. Hope this is sufficient.
-
repo owner - removed milestone
Removing milestone: 0.5.0 (automated comment)
- Log in to comment
test case illustrating the current and desired behavior