Skip to content

Commit

Permalink
fix converting default functions into string version during json-sche…
Browse files Browse the repository at this point in the history
…ma conversion
  • Loading branch information
phenobarbital committed Jun 5, 2024
1 parent 10570b6 commit 6a2916a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion datamodel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ def schema(cls, as_dict=False):
fields[name]["attrs"]["visible"] = False

if field.default:
fields[name]['default'] = field.default
d = field.default
if is_callable(d):
fields[name]['default'] = f"fn:{d!r}"
else:
fields[name]['default'] = f"{d!s}"

if secret is not None:
fields[name]['secret'] = secret
Expand Down
2 changes: 1 addition & 1 deletion datamodel/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__title__ = 'python-datamodel'
__description__ = ('simple library based on python +3.8 to use Dataclass-syntax'
'for interacting with Data')
__version__ = '0.6.25'
__version__ = '0.6.26'
__author__ = 'Jesus Lara'
__author_email__ = '[email protected]'
__license__ = 'BSD'
2 changes: 1 addition & 1 deletion examples/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class User(BaseModel):
"""
User Basic Structure
"""
id: uuid.UUID = Column(primary_key=True, required=True, default=auto_now_add(), db_default='uuid_generate_v4()')
id: uuid.UUID = Column(primary_key=True, required=True, default=auto_now_add, db_default='uuid_generate_v4()')
firstname: str
lastname: str
bignumber: np.int64
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def readme():
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Framework :: AsyncIO",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
Expand Down Expand Up @@ -157,7 +158,7 @@ def readme():
test_suite='tests',
ext_modules=cythonize(extensions),
project_urls={ # Optional
"Source": "https://github.com/phenobarbital/datamodels",
"Source": "https://github.com/phenobarbital/datamodel",
"Funding": "https://paypal.me/phenobarbital",
"Say Thanks!": "https://saythanks.io/to/phenobarbital",
},
Expand Down

0 comments on commit 6a2916a

Please sign in to comment.