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

Any type for pydbantic DataBaseModel #58

Open
ftasbasi opened this issue Apr 25, 2023 · 1 comment
Open

Any type for pydbantic DataBaseModel #58

ftasbasi opened this issue Apr 25, 2023 · 1 comment
Labels
help wanted Extra attention is needed next_release

Comments

@ftasbasi
Copy link

ftasbasi commented Apr 25, 2023

Your environment
pydbantic Version: 0.0.38
Python Version: 3.9

What happened?
I was trying to create a sample sqlite database with a simple table schema as following

from typing import Dict, Any
from pydbantic import DataBaseModel, Database

class XTable(DataBaseModel):
    attr1: str
    attr2: Dict[str, Any]
    
db = Database.create(
    f'sqlite:///zzz.db',
    tables=[XTable]
)

What did you expect to happen?
zzz.db to be created with XTable inside

Steps to reproduce
Run the code above

What is the error?

Traceback (most recent call last):
  File "/Users/me/xxx/yyy/hebele.py", line 12, in <module>
    db = Database.create(
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/database.py", line 655, in create
    new_db = cls(
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/database.py", line 81, in __init__
    self.add_table(table)
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/database.py", line 163, in add_table
    table.setup(self)
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/core.py", line 516, in setup
    cls.update_backward_refs()
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/core.py", line 670, in update_backward_refs
    data_base_model = cls.check_if_subtype({"type": model_field.type_})
  File "/Users/me/xxx/yyy/lib/python3.9/site-packages/pydbantic/core.py", line 441, in check_if_subtype
    elif issubclass(field["type"], DataBaseModel):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

when i use my own type like Union[str, int] instead of Any, it works.
It seems like Any is not supported here.
Am I missing something?

@codemation
Copy link
Owner

@ftasbasi , you are spot on, Any type is not currently supported because it is not explicit enough for serialization. I will still mark this one as a potential fix to notify users away from Any usage instead of the current more cryptic issubclass error

@codemation codemation added help wanted Extra attention is needed next_release labels Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed next_release
Projects
None yet
Development

No branches or pull requests

2 participants