Passing types.NullType to schema.Column constructor can lead to infinite recursion

Issue #1907 resolved
Former user created an issue

Introduced in 0.6beta2, present in 0.6.4.

Even though the documentation for schema.Column.init() states that a type's class can be passed for the type if no arguments are required, passing the NullType type (instead of the NULLTYPE instance) results in infinite recursion if both sides of an expression are null-typed.

Minimal reproduction of issue:

import sqlalchemy
qux = sqlalchemy.schema.Column('foo', sqlalchemy.types.NullType) + sqlalchemy.schema.Column('bar', sqlalchemy.types.NullType)

Tail of output:

/var/lib/python-support/python2.5/sqlalchemy/types.py in _adapt_expression(self, op, othertype)
    640 
    641     def _adapt_expression(self, op, othertype):
--> 642         if othertype is NULLTYPE or not operators.is_commutative(op):
    643             return op, self
    644         else:

<type 'exceptions.RuntimeError'>: maximum recursion depth exceeded

The issue can be fixed by changing the following line in types.py (from the definition of class NullType) from:

if othertype is NULLTYPE or not operators.is_commutative(op):

to:

if type(othertype) == NullType or not operators.is_commutative(op):

(The original failure was due to the Column constructor creating another NullType instance which is not the same instance as types.NULLTYPE, and thus the "is" check fails.)

Comments (3)

  1. Log in to comment