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

AttributeError: 'super' object has no attribute 'parse_obj' when using OpenAPISpec.from_file #9520

Open
1 of 14 tasks
elliexcoding opened this issue Aug 21, 2023 · 14 comments
Open
1 of 14 tasks
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules

Comments

@elliexcoding
Copy link

elliexcoding commented Aug 21, 2023

System Info

Langchain version 0.0.268

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

  1. Load in .yaml file containing the OpenAPI specification.
  2. Call the OpenAPISpec with 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.

@dosubot dosubot bot added Ɑ: models Related to LLMs or chat model modules 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Aug 21, 2023
@dosubot
Copy link

dosubot bot commented Aug 21, 2023

🤖

Hello,

The error you're encountering, 'super' object has no attribute 'parse_obj', is likely due to the fact that the 'parse_obj' method is not available in the superclass of 'OpenAPISpec'.

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.

Sources


This 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.

@kreneskyp
Copy link
Contributor

Also affecting

  • OpenAPISpec.from_url
  • get_openapi_chain

The get_openapi_chain error is hidden, but I confirmed it's the same error as above.

File "/usr/local/lib/python3.11/site-packages/langchain/chains/openai_functions/openapi.py", line 272, in get_openapi_chain
    raise ValueError(f"Unable to parse spec from source {spec}")

@kreneskyp
Copy link
Contributor

cc @baskaryan @eyurtsev

Tracked this regression to openapi-schema-pydantic being switched to an optional dependency (#9408).

Work around:

install openapi-schema-pydantic into your environment.

Root cause:

  1. OpenAPISpec's parent class defaults to object when openapi-schema-pydantic is unavailable.

    https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/openapi.py#L54-L57

  2. This leads to an exception in OpenAPISpec.parse_obj when it calls super().parse_obj().

    https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/utilities/openapi.py#L201-L202

@batmanscode
Copy link

Thanks for looking into it and figuring out a workaround @kreneskyp

Unfortunately for me installing openapi-schema-pydantic didn't work

@EnkrateiaLucca
Copy link

Having the same issue, installing openaiapi-schema-pydantic did not work. :(

eyurtsev pushed a commit that referenced this issue Oct 19, 2023
- **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.
@kreneskyp
Copy link
Contributor

Having the same issue, installing openaiapi-schema-pydantic did not work. :(

I ran into this issue again when using Pydantic 2.0 with LangChain.

Try langchain==0.0.319 with openapi-pydantic==0.3.2. Hopefully fixes all the issues now!

@PizBernina
Copy link

Having the same issue, installing openaiapi-schema-pydantic did not work. :(

I ran into this issue again when using Pydantic 2.0 with LangChain.

Try langchain==0.0.319 with openapi-pydantic==0.3.2. Hopefully fixes all the issues now!

This resolved the issue for me, cheers!

@borisko123
Copy link

openapi_schema_pydantic is changed to:
openapi-pydantic 0.3.2 (last version)
install it when using langchain

@jepsenwan
Copy link

openapi_schema_pydantic is changed to:
openapi-pydantic 0.3.2 (last version)
install it when using langchain

This works perfectly fine, thanks for the advise.

@marufaytekin
Copy link

openapi_schema_pydantic is changed to:
openapi-pydantic 0.3.2 (last version)
install it when using langchain

This worked fine, thanks for the advise.

@payamsaremi
Copy link

"pip install openapi-pydantic" fixed it for me

hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 2, 2024
- **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.
@xinyangfan
Copy link

langchain 0.1.9
openapi-pydantic 0.4.0
Still having this issue

@prova
Copy link

prova commented Mar 20, 2024

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.

@ChanduTadanki
Copy link

openapi_schema_pydantic is changed to: openapi-pydantic 0.3.2 (last version) install it when using langchain

That solved my issue. Thanks.
Note: (1) I also had to restart the kernel, (2) remove the imports from openapi_schema_pydantic, and (3) include imports from openapi-pydantic only.
More details here: https://community.deeplearning.ai/t/attributeerror-super-object-has-no-attribute-parse-obj/481376/11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests