Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_constraint=False not respected when inherited #4341

Closed
sqlalchemy-bot opened this issue Sep 25, 2018 · 13 comments
Closed

create_constraint=False not respected when inherited #4341

sqlalchemy-bot opened this issue Sep 25, 2018 · 13 comments
Labels
bug Something isn't working sql
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by moon cake (@mooncake4132)

Test case:

import enum

from sqlalchemy import Column, Enum, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import CreateTable


TableBase = declarative_base()


class Language(enum.Enum):
    english = 'English'


class Test(TableBase):
    __tablename__ = 'enum'

    id = Column(Integer, primary_key=True)
    language = Column(Enum(Language, native_enum=False, create_constraint=False))


class TestBase(TableBase):
    __abstract__ = True

    id = Column(Integer, primary_key=True)
    language = Column(Enum(Language, native_enum=False, create_constraint=False))


class TestInherited(TestBase):
    __tablename__ = 'enum_inherited'


print(CreateTable(Test.__table__))
print(CreateTable(TestInherited.__table__))

Output:

CREATE TABLE enum (
        id INTEGER NOT NULL,
        language VARCHAR(7),
        PRIMARY KEY (id)
)



CREATE TABLE enum_inherited (
        id INTEGER NOT NULL,
        language VARCHAR(7),
        PRIMARY KEY (id),
        CONSTRAINT language CHECK (language IN ('english'))
)

Expected Output: enum_inherited to be the same as enum (i.e. to not include CHECK constraint)

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by moon cake (@mooncake4132):

  • edited description

3 similar comments
@sqlalchemy-bot
Copy link
Collaborator Author

Changes by moon cake (@mooncake4132):

  • edited description

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by moon cake (@mooncake4132):

  • edited description

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by moon cake (@mooncake4132):

  • edited description

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by moon cake (@mooncake4132):

  • changed title from "create_constraint=False not respected when inherit" to "create_constraint=False not respected when inherit"

@sqlalchemy-bot
Copy link
Collaborator Author

moon cake (@mooncake4132) wrote:

I think the solution is to add kw.setdefault('create_constraint', self.create_constraint) to adapt_to_emulated: https://bitbucket.org/mooncake4132/sqlalchemy/commits/88478d15af91d6c2a56d9749337ccfc8b86246c8

I was going to create a PR, but it seems like PRs aren't enabled in this repo.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

bitbucket doesn't give me the option to disable PRs so I am sure they are enabled, however most of the work is creating the test case and the changelog message so I'll just work on that unless you are highly motivated to do all that.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

thanks for the clear test case.

https://gerrit.sqlalchemy.org/#/q/I978be65f33a616fe4d5f5de03fb3eaab6f6a2272

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "1.2.x"

@sqlalchemy-bot
Copy link
Collaborator Author

moon cake (@mooncake4132) wrote:

Thanks!

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Copy create_constraint flag for Enum

Fixed bug where the :paramref:.Enum.create_constraint flag on the
:class:.Enum datatype would not be propagated to copies of the type, which
affects use cases such as declarative mixins and abstract bases.

Fixes: #4341
Change-Id: I978be65f33a616fe4d5f5de03fb3eaab6f6a2272

0737f45

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Copy create_constraint flag for Enum

Fixed bug where the :paramref:.Enum.create_constraint flag on the
:class:.Enum datatype would not be propagated to copies of the type, which
affects use cases such as declarative mixins and abstract bases.

Fixes: #4341
Change-Id: I978be65f33a616fe4d5f5de03fb3eaab6f6a2272
(cherry picked from commit 0737f45)

fa4222e

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working sql labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 1.2.x milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql
Projects
None yet
Development

No branches or pull requests

1 participant