Skip to content

refactor: consolidate duplicated class-import logic between core/serialization and type_serialization#11897

Closed
davidsbatista wants to merge 5 commits into
v3from
refactor/consolidate-import-class-by-name
Closed

refactor: consolidate duplicated class-import logic between core/serialization and type_serialization#11897
davidsbatista wants to merge 5 commits into
v3from
refactor/consolidate-import-class-by-name

Conversation

@davidsbatista

@davidsbatista davidsbatista commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • partly fixes #450

Proposed Changes:

  • import_class_by_name (core/serialization.py) and deserialize_type (utils/type_serialization.py) each reimplemented the same "split a dotted path, import the module, getattr the class" logic.
  • Moved the shared logic into type_serialization.py as _import_class_by_name
  • While removing the now-unused logging import from core/serialization.py, caught a real bug: components/tools/tool_invoker.py was accidentally importing logging through core/serialization.py instead of from haystack directly
  • Fixed that import to go straight to haystack.logging

How did you test it?

  • Ran the full test suite, all tests pass, including the ones that caught the tool_invoker.py regression before it shipped.

Notes for the reviewer

  • import_class_by_name is now a one-line wrapper around _import_class_by_name which is private to type_serialization.py, and 9 files import import_class_by_name from core/serialization.py
  • Keeping this wrapper avoids either exposing a private name externally or touching 9 call sites for no functional gain.
  • Same pattern exists for deserialize_chatgenerator_inplace wrapping deserialize_component_inplace
  • Happy to discuss if we should change this

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

HaystackBot and others added 4 commits July 7, 2026 08:24
Co-authored-by: sjrl <10526848+sjrl@users.noreply.github.com>
Co-authored-by: Julian Risch <julian.risch@deepset.ai>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Jul 7, 2026 1:00pm

Request Review

@github-actions github-actions Bot added topic:core type:documentation Improvements on the docs labels Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/tools
  tool_invoker.py
  haystack/core
  serialization.py
  haystack/utils
  type_serialization.py 188-189
Project Total  

This report was generated by python-coverage-comment-action

@davidsbatista davidsbatista changed the title refactor: consolidate duplicated class-import logic between core/seri… refactor: consolidate duplicated class-import logic between core/serialization and type_serialization Jul 7, 2026
@davidsbatista davidsbatista marked this pull request as ready for review July 7, 2026 13:05
@davidsbatista davidsbatista requested a review from a team as a code owner July 7, 2026 13:05
@davidsbatista davidsbatista requested review from bogdankostic and removed request for a team July 7, 2026 13:05
@claude

claude Bot commented Jul 7, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@davidsbatista davidsbatista changed the base branch from main to v3 July 7, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:core type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants