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

False positive unsubscriptable-object for Pydantic model with dict Field #9968

Open
MartinGotelli opened this issue Sep 25, 2024 · 0 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Lib specific 💅 This affect the code from a particular library

Comments

@MartinGotelli
Copy link

MartinGotelli commented Sep 25, 2024

Bug description

"""
With the new LangChain version (0.3.0) there is support for Pydantic V2,
they changed all the models to use Pydantic V2, and some of our code is
returning a false positive specifically related to the BaseMessage class.
"""

# Error
from langchain_core.messages import BaseMessage

def my_function():
    message = BaseMessage(content="x", type="system")
    message.additional_kwargs["foo"] = "bar"


# Not error
from langchain_core.messages import BaseMessage
from langchain_core.pydantic_v1 import Field
# Note: with from pydantic.v1 import Field fails too

class MyBaseMessage(BaseMessage):
    additional_kwargs: dict = Field(default_factory=dict)

def my_function():
    message = BaseMessage(content="x", type="system")
    message.additional_kwargs["foo"] = "bar"

Configuration

No response

Command used

poetry run pylint app tests scripts

Pylint output

************* Module tests.unit.generators.chat_histories.test_chat_message_enricher
tests/unit/generators/chat_histories/test_chat_message_enricher.py:17:26: E1135: Value 'enriched_message.additional_kwargs' doesn't support membership test (unsupported-membership-test)
tests/unit/generators/chat_histories/test_chat_message_enricher.py:18:22: E1136: Value 'enriched_message.additional_kwargs' is unsubscriptable (unsubscriptable-object)

Expected behavior

Not a unsuscriptable-object error

Pylint version

pylint 3.2.7
astroid 3.3.4

Also reproducible on last versions

OS / Environment

Mac ARM

Additional dependencies

langchain-core==0.3.0
pydantic==2.9.1
@MartinGotelli MartinGotelli added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 25, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Help wanted 🙏 Outside help would be appreciated, good for new contributors False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Lib specific 💅 This affect the code from a particular library
Projects
None yet
Development

No branches or pull requests

2 participants