Skip to content

Any type for pydbantic DataBaseModel #58

@ftasbasi

Description

@ftasbasi

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions