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

Failure to retrieve schemas #171

Closed
tonyfujs opened this issue Jan 13, 2025 · 3 comments · Fixed by #173
Closed

Failure to retrieve schemas #171

tonyfujs opened this issue Jan 13, 2025 · 3 comments · Fixed by #173
Assignees
Milestone

Comments

@tonyfujs
Copy link

Hello - I am trying to retrieve schemas using the get_schema method, but get a validation error. Please see the reproducible code chunk and screenshot of the error below:

import pysdmx as px
from pysdmx.api import fmr
imf = fmr.AsyncRegistryClient("https://sdmxcentral.imf.org/sdmx/v2/")
# Checking that the connection works
resp = await imf.get_codes("IMF", "CL_AREA", "1.16")
resp
# Failing request
schema = await imf.get_schema("datastructure", "IMF", "BOP", "2.3")

image

@sosna sosna self-assigned this Jan 13, 2025
@sosna sosna added this to the 1.0 milestone Jan 13, 2025
@sosna
Copy link
Collaborator

sosna commented Jan 15, 2025

Hi @tonyfujs. Thank you for reporting the issue.

sdmx-json defines a property called dataType, as can be seen in the SDMX-JSON v2.0.0 schemas. However, in the ouput of the IMF Registry, it is called textType instead.

This is a bug that used to affect the FMR but has been solved in version 11.18.1. However, I see that the IMF is using version 11.15.0, i.e. a version prior the fix. Please note that there were multiple issues with the SDMX-JSON output generated by the FMR before version 11.18.1, so it might be worth suggesting an upgrade.

In the meantime, a workaround would be to use Fusion-JSON as format, instead of SDMX-JSON, as can be seen in the code snippet below.

from pysdmx.api import fmr

imf = fmr.RegistryClient(
    "https://sdmxcentral.imf.org/sdmx/v2/",
    format=fmr.Format.FUSION_JSON
)
schema = imf.get_schema("datastructure", "IMF", "BOP", "2.3")
print(schema)

I hope this helps but else, please reopen the issue.

@sosna sosna closed this as completed Jan 15, 2025
@tonyfujs
Copy link
Author

Thanks @sosna - Specifying the format indeed solved the issue with the IMF API. It did not solved it for our internal instance of FMR though. The error is no longer the same, but I am still getting an error (please see below). We are not using the most recent version of FMR, the version we currently have deployed internally is 11.17.2: Could this be the cause of the problem? Thanks!

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[16], line 3
      1 #schema = await client.get_schema("dataflow", "WB.DATA360", "DF_DATA360", "1.0")
      2 # schema = await client.get_schema("datastructure", "WB.DATA360", "DS_DATA360", "1.2")
----> 3 schema = client.get_schema("datastructure", "WB.DATA360", "DS_DATA360", "1.2")
      4 # schema = await imf.get_schema("datastructure", "IMF", "BOP", "2.3")
      5 schema.agency

File c:\Users\WB499754\wb-projects\SDMX\tools\pysdmx-test\.venv\Lib\site-packages\pysdmx\api\fmr\__init__.py:555, in RegistryClient.get_schema(self, context, agency, id, version)
    553 url = super()._schema_url(c, agency, id, version)
    554 out = self.__fetch(f"{self.api_endpoint}{url}")
--> 555 return super()._out(
    556     out, self.deser.schema, c.value, agency, id, version, ha
    557 )

File c:\Users\WB499754\wb-projects\SDMX\tools\pysdmx-test\.venv\Lib\site-packages\pysdmx\api\fmr\__init__.py:109, in __BaseRegistryClient._out(self, response, typ, *params)
    108 def _out(self, response: bytes, typ: Deserializer, *params: Any) -> Any:
--> 109     return decode(response, type=typ).to_model(*params)

ValidationError: Object missing required field `title` - at `$.Codelist[9].items[0].annotations[0]`

@sosna
Copy link
Collaborator

sosna commented Jan 15, 2025

No, I'm afraid the issue is different this time but it is easy to fix. I will reopen this ticket and will provide a fix later this week.

@sosna sosna reopened this Jan 15, 2025
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

Successfully merging a pull request may close this issue.

2 participants