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

Type serialization/deserialization failure with PEP-585 generics #7609

Closed
1 task done
mikebellerU opened this issue Apr 28, 2024 · 2 comments · Fixed by #7690
Closed
1 task done

Type serialization/deserialization failure with PEP-585 generics #7609

mikebellerU opened this issue Apr 28, 2024 · 2 comments · Fixed by #7690
Assignees
Labels
P1 High priority, add to the next sprint type:bug Something isn't working
Milestone

Comments

@mikebellerU
Copy link

Describe the bug

I receive a PipelineConnect error if I try to deserialize a pipeline containing a
component with output type list[Document]. If I change to List[Document], the error
goes away.

Error message
Error that was thrown (if available)

haystack.core.errors.PipelineConnectError: Cannot connect 'mux.value' with 'paris_router.documents': their declared input and output types do not match.
'mux':
 - value: list
'paris_router':
 - documents: List[Document] (available)

Expected behavior

Expected no error. Per PEP-585 (implemented originally in Python 3.9)

Additional context

It's possible one could view this as a documentation problem -- in that it is not documented
that list[X] and List[X] are not treated the same by the deserialization mechanism, but it
seems a bit of a "gotcha" to me.

To Reproduce

Example:

Run the following code:

from haystack import Document, Pipeline
from haystack.components.others import Multiplexer
from haystack.components.routers import MetadataRouter

p = Pipeline()
p.add_component("mux", Multiplexer(list[Document]))
p.add_component("paris_router", MetadataRouter(
    rules={"city": {"field": "meta.city", "operator": "==", "value": "Paris"}}))
p.connect("mux.value", "paris_router.documents")
s = p.dumps()
print(s)
p2 = Pipeline.loads(s)

To work around, just replace list[Document] with List[Document] (and import List from typing module obvi)

FAQ Check

System:

  • OS: Linux Ubuntu 22.04
  • GPU/CPU: Intel
  • Haystack version (commit or version number): both 2.0.1, and tested also with 8d04e53
  • DocumentStore: none
  • Reader: none
  • Retriever: none
@masci masci added type:bug Something isn't working P1 High priority, add to the next sprint labels May 6, 2024
@shadeMe shadeMe added this to the 2.1.2 milestone May 13, 2024
@mrm1001
Copy link
Member

mrm1001 commented May 13, 2024

Hi there, thanks for writing such a detailed issue, we are looking into it! I am the product manager of the library and I like to reach out to users to get feedback and see how we could help. Let me know if you would be available some time this week for a 15 min chat (calendly).

@mikebellerU
Copy link
Author

mikebellerU commented May 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority, add to the next sprint type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants