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

Changing custom_schema file results in unexpected validation #1861

Open
braingram opened this issue Nov 1, 2024 · 0 comments
Open

Changing custom_schema file results in unexpected validation #1861

braingram opened this issue Nov 1, 2024 · 0 comments
Milestone

Comments

@braingram
Copy link
Contributor

Description of the problem

Overwriting a file used for custom_schema results in validation that uses the old file contents. This came up while attempting to use it in a jupyter notebook where this type of error seems likely to occur (as with any interactive session).

This may be due to schema caching. Perhaps not caching custom_schema would fix this.

Example of the problem

import asdf

schema_contents = """%YAML 1.1
---
id: "http://example.com/schemas/your-custom-schema"
$schema: "http://stsci.edu/schemas/yaml-schema/draft-01"
type: object
properties:
  value:
      type: integer"""


with open("my_schema.yaml", "w") as f:
    f.write(schema_contents)

af = asdf.AsdfFile(custom_schema="my_schema.yaml")
# af["value"] = "a"
# af.validate()  will correctly raise a ValidationError
af["value"] = 1
af.validate()

schema_contents = """%YAML 1.1
---
id: "http://example.com/schemas/your-custom-schema"
$schema: "http://stsci.edu/schemas/yaml-schema/draft-01"
type: object
properties:
  number:
      value: string"""

with open("my_schema.yaml", "w") as f:
    f.write(schema_contents)

af = asdf.AsdfFile(custom_schema="my_schema.yaml")
af["value"] = "a"
af.validate()  # incorrectly raise a ValidationError

System information

asdf version: main
python version: 3.10
operating system: mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant