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

Error get_replication_policies #68

Open
lukonjun opened this issue Nov 29, 2023 · 2 comments
Open

Error get_replication_policies #68

lukonjun opened this issue Nov 29, 2023 · 2 comments

Comments

@lukonjun
Copy link

lukonjun commented Nov 29, 2023

Hi, when running get_replication_policies I run into an error

Traceback (most recent call last):
  File "main2.py", line 21, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "main2.py", line 18, in main
    replication = await client.get_replication_policies()
  File "/home/lucas/.local/lib/python3.8/site-packages/harborapi/client.py", line 1246, in get_replication_policies
    return self.construct_model(ReplicationPolicy, resp, is_list=True)
  File "/home/lucas/.local/lib/python3.8/site-packages/harborapi/client.py", line 420, in construct_model
    return [self._construct_model(cls, item) for item in data]
  File "/home/lucas/.local/lib/python3.8/site-packages/harborapi/client.py", line 420, in <listcomp>
    return [self._construct_model(cls, item) for item in data]
  File "/home/lucas/.local/lib/python3.8/site-packages/harborapi/client.py", line 432, in _construct_model
    raise e
  File "/home/lucas/.local/lib/python3.8/site-packages/harborapi/client.py", line 427, in _construct_model
    return cls.parse_obj(data)
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for ReplicationPolicy
filters -> 0 -> value
  value is not a valid dict (type=type_error.dict)
filters -> 1 -> value
  value is not a valid dict (type=type_error.dict)

This is the code I use

async def main() -> None:
    replication = await client.get_replication_policies()
    print(replication)

asyncio.run(main())

Any advice how to fix this, is this an api incompability with the client? I am using harbor version v2.9.0

@Soopx
Copy link

Soopx commented Feb 3, 2024

I get a similar error, and it appears that the reason is that the function returns a list, when the model demands a dictionary:

pydantic_core._pydantic_core.ValidationError: 2 validation errors for ReplicationPolicy filters.0.value Input should be a valid dictionary [type=dict_type, input_value='**/hello-world', input_type=str] For further information visit https://errors.pydantic.dev/2.5/v/dict_type filters.1.value Input should be a valid dictionary [type=dict_type, input_value='**', input_type=str] For further information visit https://errors.pydantic.dev/2.5/v/dict_type

It seems that both of these should be wrapped in a list, but they themselves should be dictionaries. I'm assuming this is an error with Harbor rather than the API, but it would be nice if it could be fixed somehow

@Soopx
Copy link

Soopx commented Feb 5, 2024

I've found the issue. In harborapi/models/model.py on line 493, it shows that "value" in the ReplicationFilter class is expecting a dictionary, but it's stored as a string. Editing this line to expect a string fixes the issue for me. Can this be tested and implemented please?

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

2 participants