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

Pydantic dataclasses causes problems with sqlalchemy classic mappers #1403

Closed
sandys opened this issue Apr 17, 2020 · 1 comment
Closed

Pydantic dataclasses causes problems with sqlalchemy classic mappers #1403

sandys opened this issue Apr 17, 2020 · 1 comment
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@sandys
Copy link

sandys commented Apr 17, 2020

# from dataclasses import field
from pydantic.dataclasses import dataclass
from typing import List
from datetime import datetime
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, ARRAY, TIMESTAMP
from sqlalchemy.orm import sessionmaker, mapper

metadata = MetaData()
person_table = \
    Table('people', metadata,
          Column('id', Integer, primary_key=True, autoincrement=True),
          Column('name', String(255)),
          Column('age', Integer),
          Column('hobbies', String),
          Column('birthday', TIMESTAMP)
          )

@dataclass
class Person:
    id: int = None
    name: str = ''
    age: int = 0
    hobbies: str = None
    birthday: datetime = None

mapper(Person, person_table)

engine = create_engine("sqlite:///", echo=True)
metadata.create_all(engine)

session = sessionmaker(bind=engine)()
person = Person(id=None, name='Robby', age=33, hobbies="golf", birthday=datetime(1985, 7, 25))
session.add(person)
session.commit()

this works if i replace pydantic dataclasses with standard python dataclasses.

how can this be fixed ?

@sandys sandys added the bug V1 Bug related to Pydantic V1.X label Apr 17, 2020
@sandys
Copy link
Author

sandys commented Apr 17, 2020

im closing this myself, since i saw #1089 and understand that this is a known WONTFIX issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

No branches or pull requests

2 participants