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

Add support for SET column type [wishlist] #31

Open
ernstki opened this issue Mar 7, 2018 · 2 comments
Open

Add support for SET column type [wishlist] #31

ernstki opened this issue Mar 7, 2018 · 2 comments

Comments

@ernstki
Copy link

ernstki commented Mar 7, 2018

sqlacodegen seems to work fine with ENUM types; SETs are a different story.

If you attempt to run on a database with a SET column type, such as the following:

CREATE TABLE `tools_datasets` (
    `tool_id` int(11) NOT NULL,
    `dataset_id` int(11) NOT NULL,
    `status` SET('p','i','e') DEFAULT 'i,e',
    PRIMARY KEY (`tool_id`,`dataset_id`),
);

you'll get an error like this:

$ flask-sqlacodegen --version
1.1.6.1
$ flask-sqlacodegen --tables tools_datasets $DBCONN
Traceback (most recent call last):
  File "/Users/user/path/to/project/venv/bin/flask-sqlacodegen", line 11, in <module>
    sys.exit(main())
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/main.py", line 59, in main
    args.flask, ignore_cols, args.noclasses)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 606, in __init__
    model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 309, in __init__
    super(ModelClass, self).__init__(table)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 248, in __init__
    column.type = column.type.adapt(cls)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/enumerated.py", line 310, in adapt
    **kw
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 1045, in constructor_copy
    return cls(*args, **kw)
TypeError: __init__() got an unexpected keyword argument 'retrieve_as_bitwise'

I know that the SET column type is kind of out in the weeds (maybe it's better to just use a many-to-many relationship), but honestly, is ENUM is kind of in that category, too , so maybe we could work to support SET as well.

@ksindi
Copy link
Owner

ksindi commented Mar 7, 2018

Thanks for creating the issue @ernstki

@leocxy
Copy link

leocxy commented Dec 3, 2020

@ksindi
Hi, I got the same issue.

I am using:

  • flask-sqlacodegen 1.1.8
  • SQLAlchemy 1.3.20

I found this issue has been fixed by the latest version of sqlacodegen library.

Here is the link agronholm/sqlacodegen#85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants