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

Use Safe repr If Parent Pybind11 Constructor Fails #1545

Merged
merged 1 commit into from
Jan 6, 2023

Conversation

nguyenv
Copy link
Collaborator

@nguyenv nguyenv commented Jan 5, 2023

  • This fixes a larger scale issue that was originally caught in the SOMA unit tests [python] Do not use extent 2048 on 8-bit index types single-cell-data/TileDB-SOMA#653
  • When the parent Pybind11 constructor fails, Pytest prints a backtrace of all the arguments in super().__init__() which includes the self object. Since the object does not exist, using the Pybind11 wrapped properties, namely _filters, results in a segfault
  • We use self._ctx, which is a property that only exists on the pure Python object, to check if the object has been properly instantiated

* This fixes a larger scale issue that was originally caught in
  the SOMA unit tests single-cell-data/TileDB-SOMA#653
* When the parent Pybind11 constructor fails, Pytest prints a backtrace
  of all the arguments in `super().__init__()` which includes the `self`
  object. Since the object does not exist, using the Pybind11 wrapped
  properties, namely `_filters`, results in a segfault
* We use `self._ctx`, which is a property that only exists on the pure
  Python object, to check if the object has been properly instantiated
@nguyenv
Copy link
Collaborator Author

nguyenv commented Jan 5, 2023

A few additional comments:

  • We do actually use Dim._ctx here
  • Updating self._ctx after the super() ended up making the code more confusing to follow, so I've only set it to None when it errors out when calling the parent constructor

@nguyenv nguyenv requested a review from ihnorton January 5, 2023 22:24
@gsakkis gsakkis mentioned this pull request Jan 6, 2023
@nguyenv nguyenv requested a review from johnkerl January 6, 2023 21:01
@nguyenv nguyenv merged commit cd30189 into dev Jan 6, 2023
@nguyenv nguyenv deleted the viviannguyen/segfault-in-dim-constructor branch January 6, 2023 21:01
Copy link
Contributor

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

Wow thanks @nguyenv !! This is "super"!!!! :D

ihnorton pushed a commit that referenced this pull request Jan 11, 2023
- DRY-fy #1545 (cd30189)
- Apply the fix to two more classes with the same issue (`Domain`, `Group`)
@nguyenv nguyenv mentioned this pull request Jan 18, 2024
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.

3 participants