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

AutoLangConfig for Label Doesn't Seem to Work in this Case #213

Open
markpbaggett opened this issue Dec 9, 2024 · 2 comments
Open

AutoLangConfig for Label Doesn't Seem to Work in this Case #213

markpbaggett opened this issue Dec 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@markpbaggett
Copy link
Contributor

When using the library, a common pattern is to set an auto language across the manifest so that you don't need to set the language each time. For instance:

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"
base_url = "https://iiif.io/api/cookbook/recipe/0001-mvm-image"
manifest = Manifest(id=f"{base_url}/manifest.json", label="Single Image Example")

With this, the lang of the label would be 'en'. For some reason, that pattern doesn't work in this case:

config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en"
natural_light = ResourceItem(
    id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg",
    type="Image",
    format="image/jpeg",
    width=2000,
    height=1271,
    label="Natural Light"
)

Instead, this results in:

Traceback (most recent call last):
  File "/Users/mark.baggett/code/iiif-prezi3/testing3.py", line 14, in <module>
    natural_light = ResourceItem(
        id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg",
    ...<4 lines>...
        label="Natural Light"
    )
  File "/Users/mark.baggett/code/iiif-prezi3/iiif_prezi3/base.py", line 46, in __init__
    super().__init__(**kw)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/mark.baggett/code/iiif-prezi3/venv/lib/python3.13/site-packages/pydantic/main.py", line 341, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 2 validation errors for ResourceItem
label -> __root__
  value is not a valid dict (type=type_error.dict)
label -> __root__
  value is not a valid dict (type=type_error.dict)

Expected behaviour:

I expected to be able to set the language for the ResourceItem with config.configs['helpers.auto_fields.AutoLang'].auto_lang = "en".

Observed behaviour:

An error was raised:

Traceback (most recent call last):
  File "/Users/mark.baggett/code/iiif-prezi3/testing3.py", line 14, in <module>
    natural_light = ResourceItem(
        id="https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg",
    ...<4 lines>...
        label="Natural Light"
    )
  File "/Users/mark.baggett/code/iiif-prezi3/iiif_prezi3/base.py", line 46, in __init__
    super().__init__(**kw)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/mark.baggett/code/iiif-prezi3/venv/lib/python3.13/site-packages/pydantic/main.py", line 341, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 2 validation errors for ResourceItem
label -> __root__
  value is not a valid dict (type=type_error.dict)
label -> __root__
  value is not a valid dict (type=type_error.dict)

Potential bug location(s):

Not sure yet. I looked in auto_fields.py, but I haven't spotted the problem yet.

Any other comments:

@markpbaggett markpbaggett added the bug Something isn't working label Dec 9, 2024
@glenrobson
Copy link
Contributor

As ResourceItem inherites from Base not Class it needs to be added directly here:

https://github.com/iiif-prezi/iiif-prezi3/blob/daf6e8a7ad41773dacb9302358c53e7d09cce58d/iiif_prezi3/helpers/auto_fields.py#L183C1-L183C55

@markpbaggett
Copy link
Contributor Author

Addressed in 214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants