Skip to content

copt: treat PyObject_IsTrue errors as failures in IB__adapt__ - #396

Closed
Eryx-Z wants to merge 1 commit into
zopefoundation:masterfrom
Eryx-Z:fix/adapt-isTrue-error
Closed

Eryx-Z wants to merge 1 commit into
zopefoundation:masterfrom
Eryx-Z:fix/adapt-isTrue-error

Conversation

@Eryx-Z

@Eryx-Z Eryx-Z commented Oct 16, 2026

Copy link
Copy Markdown

Summary

In IB__adapt__, the security-proxy fallback path stores PyObject_IsTrue(r) in implements and then tests if (implements). A -1 error result is truthy in C, so the adapted object was returned with a pending exception still set.

Check implements < 0 and return NULL, matching the PyDict_Contains error handling on the fast path.

Fixes #361

Test plan

  • Patch matches the one-line fix described in the issue
  • Hard to trigger from pure Python (needs a proxy-like declaration whose call returns a broken __bool__); relying on the C API contract check

When adapting via a non-SpecificationBase declaration (e.g. security
proxy path), PyObject_IsTrue can return -1. That value was treated as
truthy, returning the object with a pending exception still set.

Fixes #361
@Eryx-Z

Eryx-Z commented Oct 17, 2026

Copy link
Copy Markdown
Author

Closing for now.

@Eryx-Z Eryx-Z closed this Oct 17, 2026
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.

copt: PyObject_IsTrue error treated as truthy in IB__adapt__

1 participant