-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
AttributeError: 'super' object has no attribute 'parse_obj' when using OpenAPISpec.from_file #9520
Comments
🤖 Hello, The error you're encountering, In LangChain, 'OpenAPISpec' is a subclass of 'OpenAPI', which is imported from the 'openapi_schema_pydantic' package. The 'parse_obj' method is called on the superclass in the 'parse_obj' method of 'OpenAPISpec': @classmethod
def parse_obj(cls, obj: dict) -> OpenAPISpec:
try:
cls._alert_unsupported_spec(obj)
return super().parse_obj(obj)
except ValidationError as e:
# We are handling possibly misconfigured specs and
# want to do a best-effort job to get a reasonable interface out of it.
new_obj = copy.deepcopy(obj)
for error in e.errors():
keys = error["loc"]
item = new_obj
for key in keys[:-1]:
item = item[key]
item.pop(keys[-1], None)
return cls.parse_obj(new_obj) The error suggests that the 'OpenAPI' class does not have a 'parse_obj' method. This could be due to a version mismatch between the 'openapi_schema_pydantic' package used in your environment and the one expected by LangChain. LangChain v0.0.268 is compatible with the 'openapi_schema_pydantic' package version "^1.2". This means any version that is compatible with version 1.2. The caret (^) symbol in "^1.2" indicates compatibility with versions up to but not including 2.0.0. This information is found in the 'pyproject.toml' file under the '[tool.poetry.dependencies]' section: openapi-schema-pydantic = {version = "^1.2", optional = true} Please ensure that you have the correct version of 'openapi_schema_pydantic' installed. If the issue persists, it might be a bug in LangChain or 'openapi_schema_pydantic', and you should consider reporting it to the maintainers. I hope this helps! Let me know if you have any other questions. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Also affecting
The
|
Tracked this regression to Work around:install Root cause:
|
Thanks for looking into it and figuring out a workaround @kreneskyp Unfortunately for me installing |
Having the same issue, installing openaiapi-schema-pydantic did not work. :( |
- **Description:** Adding Pydantic v2 support for OpenAPI Specs - **Issue:** - OpenAPI spec support was disabled because `openapi-schema-pydantic` doesn't support Pydantic v2: #9205 - Caused errors in `get_openapi_chain` - This may be the cause of #9520. - **Tag maintainer:** @eyurtsev - **Twitter handle:** kreneskyp The root cause was that `openapi-schema-pydantic` hasn't been updated in some time but [openapi-pydantic](https://github.com/mike-oakley/openapi-pydantic) forked and updated the project.
I ran into this issue again when using Pydantic 2.0 with LangChain. Try |
This resolved the issue for me, cheers! |
openapi_schema_pydantic is changed to: |
openapi_schema_pydantic is changed to: This works perfectly fine, thanks for the advise. |
openapi_schema_pydantic is changed to: This worked fine, thanks for the advise. |
"pip install openapi-pydantic" fixed it for me |
- **Description:** Adding Pydantic v2 support for OpenAPI Specs - **Issue:** - OpenAPI spec support was disabled because `openapi-schema-pydantic` doesn't support Pydantic v2: langchain-ai#9205 - Caused errors in `get_openapi_chain` - This may be the cause of langchain-ai#9520. - **Tag maintainer:** @eyurtsev - **Twitter handle:** kreneskyp The root cause was that `openapi-schema-pydantic` hasn't been updated in some time but [openapi-pydantic](https://github.com/mike-oakley/openapi-pydantic) forked and updated the project.
langchain 0.1.9 |
My colleague is facing the same issue on Python 3.10.12 and langchain==0.1.12 plus openapi-pydantic==0.4.0 (and also tried 0.3.2). On my PC, all is good with the same versions and Python. This is some random stuff. |
That solved my issue. Thanks. |
System Info
Langchain version 0.0.268
Who can help?
No response
Information
Related Components
Reproduction
open_api_spec = OpenAPISpec.from_file(file_path)
Error shows that in openapi.py line 202 ,
return super().parse_obj(obj)
no longer inherits the super method from Pydantic's BaseModel parse_obj.Expected behavior
The OpenAPISpec should be delivered so that it can be passed on to
NLAToolkit.from_llm_and_spec
.The text was updated successfully, but these errors were encountered: