MSSQL column nullability should be explicit

Issue #1243 resolved
Former user created an issue

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)

  1. Former user 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.

  2. Mike Bayer 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.

  3. Michael Trier

    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.

  4. Log in to comment