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

Possible issue with bit fields #17

Open
jkugler opened this issue Oct 5, 2015 · 0 comments
Open

Possible issue with bit fields #17

jkugler opened this issue Oct 5, 2015 · 0 comments

Comments

@jkugler
Copy link

jkugler commented Oct 5, 2015

This may be an issue with me not understanding fixtures and/or SQLAlchemy, but any assistance would be great!

I have some data dumped from an MS SQL DB, which is using BIT fields for true/false. I'm trying to load it into a PostgreSQL DB for testing. The data is exported by getting the records (via SQLAlchemy), and then looping over them and generating each dict thus:

def as_dict(r):
    d = {}

    for c in r.__table__.columns:
        o = getattr(r, c.name)
        d[c.name]= o

    return d

That works great, properly formats UUIDs and date/times. However, the bit fields come out as 'true' or 'false.' While that is what they are being used as, this then creates issues later. When I try to load them into the PG DB (again, via Flask-Fixtures), I get an exception of:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "isActive" is of type bit but expression is of type boolean

If I change the true/false entries to 1/0 in the Yaml file, I then get:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "isActive" is of type bit but expression is of type integer

Is there a way to mark them such that Flask-Fixtures will turn them back into Bit objects before it tries to insert them? Does Flask-Fixtures introspect on the column

I realize the proper answer here is "convert them to boolean fields," but this is a legacy database, and quick-and-dirty changes to the schema would not happen soon. :)

This may well be an issue with SQLAlchemy, as it seems it converts from the bit field to a true/false value when selecting, but then does not convert back when inserting the value.

How DO you pass a bit object to SQLAlchemy?

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

1 participant