Skip to content

Conversation

yaricom
Copy link
Contributor

@yaricom yaricom commented Sep 1, 2025

Details

Problem: The error handling code in the decorator was trying to access func.__name__ directly, but functools.partial objects don't have this attribute, causing AttributeError: functools.partial object has no attribute __name__.

Solution:

  1. Created a safe helper function: Added get_function_name() in src/opik/decorator/inspect_helpers.py:50-57 that safely handles functools.partial objects by
    accessing the underlying function's __name__ attribute.
  2. Fixed all usages: Updated 9 instances in src/opik/decorator/base_track_decorator.py and 1 instance in src/opik/decorator/tracker.py to use the safe helper instead
    of direct func.__name__ access.
  3. Added comprehensive tests: created unit tests for the helper function and an integration test that verifies partial functions work correctly with the tracker and their names are processed properly.

Key improvements:

  • The fix handles not just functools.partial objects but any callable without a __name__ attribute
  • Falls back to <unknown> for objects without names
  • All existing tests continue to pass
  • The integration test confirms the fix resolves the original crash scenario

The user's opik.evaluate() calls with functools.partial functions will now work correctly without crashing.

Change checklist

  • User facing

Issues

  • OPIK-937

Testing

Added comprehensive tests.

Documentation

Added doctoring where required.

… rules of the `claude code` agent in the Python SDK.
…ogging in Python SDK.

- Introduced `get_function_name` utility to handle `functools.partial` and unnamed callables.
- Updated decorators and loggers to use the new utility to avoid crashes.
- Added comprehensive tests for `get_function_name` to validate behavior across regular functions, partials, lambdas, and callables.
@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 15:53
@yaricom yaricom requested review from a team as code owners September 1, 2025 15:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a crash in Opik Evaluate when functions are wrapped in functools.partial by addressing the issue where the decorator code tried to access func.__name__ directly on partial objects that don't have this attribute.

  • Introduced a safe helper function to extract function names from both regular functions and functools.partial objects
  • Replaced all unsafe direct func.__name__ accesses with the safe helper function
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
sdks/python/src/opik/decorator/inspect_helpers.py Added get_function_name() helper function to safely extract names from functions and partial objects
sdks/python/src/opik/decorator/base_track_decorator.py Updated 9 instances to use safe helper instead of direct func.__name__ access
sdks/python/src/opik/decorator/tracker.py Updated 1 instance to use safe helper for function name extraction
sdks/python/tests/unit/decorator/test_inspect_helpers.py Added comprehensive unit tests for the new helper function
sdks/python/tests/unit/decorator/test_tracker_outputs.py Added integration test verifying partial functions work correctly with tracker
sdks/python/CLAUDE.md Added documentation file for Claude Code integration

Comment on lines +1 to +3
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Copy link
Preview

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation file appears unrelated to the PR's core purpose of fixing functools.partial compatibility. Consider moving this to a separate PR focused on documentation improvements.

Copilot generated this review using guidance from repository custom instructions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irrelevant comment.

@yaricom yaricom merged commit 0b5e4c8 into main Sep 1, 2025
88 checks passed
@yaricom yaricom deleted the yaricom/OPIK-937-evaluate-crash-funtion_partial branch September 1, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants