data_models: fix `validation_error_cause` flag error (#66)

This commit is contained in:
Sina Atalay 2024-06-01 15:12:12 +03:00
parent e739c10d24
commit 890c6b835b
1 changed files with 21 additions and 9 deletions

View File

@ -136,7 +136,7 @@ class RenderCVBaseModel(pydantic.BaseModel):
unknown key is provided in the input file. unknown key is provided in the input file.
""" """
model_config = pydantic.ConfigDict(extra="forbid", validation_error_cause=True) model_config = pydantic.ConfigDict(extra="forbid")
# ====================================================================================== # ======================================================================================
@ -275,13 +275,21 @@ class PublicationEntryBase(RenderCVBaseModel):
doi_url = f"http://doi.org/{doi}" doi_url = f"http://doi.org/{doi}"
# Validate the URL:
url_validator.validate_strings(doi_url)
try: try:
urlopen(doi_url) urlopen(doi_url)
except HTTPError as err: except HTTPError as err:
if err.code == 404: if err.code == 404:
raise ValueError("DOI cannot be found in the DOI System!") raise ValueError("DOI cannot be found in the DOI System!")
except (InvalidURL, URLError): except InvalidURL:
# Unfortunately, url_validator doesn't catch all the invalid URLs.
raise ValueError("This DOI is invalid!") raise ValueError("This DOI is invalid!")
except URLError:
# In this case, there is no internet connection, so don't raise an
# error.
pass
return doi return doi
@ -674,9 +682,7 @@ class SectionBase(RenderCVBaseModel):
because all of the section types have a common field called `title`. because all of the section types have a common field called `title`.
""" """
# Title is excluded from the JSON schema because this will be written by RenderCV title: str
# depending on the key in the input file.
title: Optional[str] = pydantic.Field(default=None, exclude=True)
entry_type: str entry_type: str
entries: list[Entry] entries: list[Entry]
@ -801,7 +807,6 @@ def validate_section_input(
try: try:
section_type.model_validate( section_type.model_validate(
test_section, test_section,
context={"section": "test"},
) )
except pydantic.ValidationError as e: except pydantic.ValidationError as e:
new_error = ValueError( new_error = ValueError(
@ -1257,10 +1262,17 @@ class RenderCVDataModel(RenderCVBaseModel):
theme_module = importlib.util.module_from_spec(spec) theme_module = importlib.util.module_from_spec(spec)
try: try:
spec.loader.exec_module(theme_module) # type: ignore spec.loader.exec_module(theme_module) # type: ignore
except SyntaxError or ImportError: except SyntaxError:
raise ValueError( raise ValueError(
f"The custom theme {theme_name}'s __init__.py file is not" f"The custom theme {theme_name}'s __init__.py file has a syntax"
" valid. Please check the file and try again.", " error. Please fix it.",
)
except ImportError:
raise ValueError(
f"The custom theme {theme_name}'s __init__.py file has an"
" import error. If you have copy-pasted RenderCV's built-in"
" themes, make sure tto update the import statements (e.g.,"
' "from . import..." to "from rendercv.themes import...").',
) )
ThemeDataModel = getattr( ThemeDataModel = getattr(