-
Notifications
You must be signed in to change notification settings - Fork 8
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
Foreign keys are not compatible with @cache #15
Comments
What version of python are you using? I have had similar issues(skill issue most likely) with fk definitions and while I have not been able to find the root cause of it ! pip install python-fasthtml
from fasthtml.common import *
schema = {'department': {'id': int, 'name': str},
'students': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': ['department_id']},
'professors': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': ['department_id']},
'classes': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': ['department_id']}}
db = Database(memory=True)
for t in db.table_names(): db.t[t].drop()
for t,meta in schema.items():
cs = meta.get('columns', meta)
fks = meta.get('foreign_keys')
db.create_table(t, cs, pk='id', foreign_keys=fks)
print(f"Python version: {sys.version}")
diagram(db.tables) When using python 3.12 you need to be more exact with the fk definitions. to get your code to work in 3.12.. schema = {'department': {'id': int, 'name': str},
'students': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': (("department_id", "department", "id"),)},
'professors': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': (("department_id", "department", "id"),)},
'classes': {'columns': {'id': int, 'name': str, 'department_id': str},
'foreign_keys': (("department_id", "department", "id"),)}}
db = Database(memory=True)
for t in db.table_names(): db.t[t].drop()
for t,meta in schema.items():
cs = meta.get('columns', meta)
fks = meta.get('foreign_keys')
db.create_table(t, cs, pk='id', foreign_keys=fks)
print(f"Python version: {sys.version}")
diagram(db.tables) |
edit looks like Its more just related to the types - must be something todo with immutable/ mutable datatypes ? 'foreign_keys': ['department_id'] # OK in 3.10 Not in 3.12 'foreign_keys': (('department_id',),) # OK in 3.12 |
We get the error
because self.table is @cache decorated and foreign keys are a list
The text was updated successfully, but these errors were encountered: