Enum validation causes problems with column_property

Issue #3833 resolved
Lukas Siemon created an issue

I'm currently trying to upgrade from 1.0.12 to 1.1.2. There is a problem where the enum validation gets propagated to column property and then fails. Any advice how to work around this for now? Adding validate_strings=False does not help unfortunately.

Error:

LookupError: "#1" is not among the defined enum values

Test Case

import unittest
from sqlalchemy import (Column, Integer)
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (column_property)
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = ("sqlite://")
db = SQLAlchemy(app)

Base = declarative_base()


class Venue(db.Model):
    __tablename__ = 'venue'
    id = Column(Integer, primary_key=True, nullable=False)

    default = Column(
        ENUM('1', name='default_enum'),
        index=True,
        nullable=True
    )
    dashed_default = column_property("#" + default)

db.drop_all()
db.create_all()


class TestSelfJoin(unittest.TestCase):

    def test_self_join(self):

        db.session.add(Venue(default="1"))
        db.session.commit()

        venue = Venue.query.one()
        print venue.default

Comments (4)

  1. Mike Bayer repo owner

    ugh. I was nervous about the "enum validation" change because I wasnt sure what it would break.

  2. Mike Bayer repo owner

    Convert expression type for concat + Enum

    Fixed bug involving new value translation and validation feature in :class:.Enum whereby using the enum object in a string concatenation would maintain the :class:.Enum type as the type of the expression overall, producing missing lookups. A string concatenation against an :class:.Enum-typed column now uses :class:.String as the datatype of the expression itself.

    Change-Id: Id402054e3ef008e0250c740dbb7e1c80f339fe78 Fixes: #3833

    → <<cset c97b1b822825>>

  3. Log in to comment