GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix: del obj[key] on a reflected indexer crashed the process by jhonabreul · Pull Request #149 · QuantConnect/pythonnet

Conversation

@jhonabreul

@jhonabreul jhonabreul commented Sep 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Problem

  • del obj[key] on any reflected type with a settable indexer crashed the process.
  • CPython uses the same mp_ass_subscript slot for assignment and deletion, with a null value for del.
  • mp_ass_subscript_impl never checked for the null and forwarded it into PyTuple_SetItem, which threw across the native boundary.
  • ArrayObject.mp_ass_subscript had the same hole and died with an access violation.
  • Official pythonnet fixed this in __delitem__ for IList<T> and IDictionary<K,V> pythonnet/pythonnet#2533; this fork predates it.

Changes

  • ClassBase: check v.IsNull first and route to the new DeleteItemImpl.
  • DeleteItemImpl: TypeError when the type has no deleter or the key is a tuple; otherwise call the deleter through the binder; false from Remove becomes KeyError.
  • Indexer: new DeleterBinder, resolved lazily on the first del from IDictionary<K,V>.Remove(K), else IList<T>.RemoveAt(int). Uses the interface method, so explicit implementations like ConcurrentDictionary.Remove work.
  • ArrayObject: TypeError on a null value.
  • Tests: nine pytest cases, a throwing Remove fixture, and an embed test fixture.

Behaviour

Target Before After
plain settable indexer, tuple key, array crash TypeError
Dictionary / ConcurrentDictionary crash key removed, KeyError if missing
List<T> crash element removed, ArgumentOutOfRangeException if out of range
deleter throws n/a catchable exception, interpreter alive

Verification

  • pytest: 477 passed, 1 pre-existing environmental failure (test_explicit_assembly_load).
  • Embed tests (Debug): 3 passed. Each new test crashes on master.
  • Lean with the patched DLL: a Python algorithm doing del self.runtime_statistics[key] now completes; 324/324 Python regression algorithms and 16600/16600 Python unit tests pass.

Follow-up

  • Stubs: Emit __delitem__ on IDictionary and IList quantconnect-stubs-generator#100 adds __delitem__ on IDictionary and IList. Ship it with or after this release.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jhonabreul
Fix: del obj[key] on a reflected indexer crashed the process
e8d8dc1
CPython calls mp_ass_subscript with a null value for del, which mp_ass_subscript_impl forwarded into PyTuple_SetItem and threw across the native boundary. Handle deletion first: IDictionary<K,V>.Remove / IList<T>.RemoveAt through the binder (KeyError on a missing dictionary key), TypeError for every other type and for arrays.
@jhonabreul jhonabreul mentioned this pull request Sep 2, 2026
Emit __delitem__ on IDictionary and IList QuantConnect/quantconnect-stubs-generator#100
Merged
@jhonabreul
Resolve the item deleter lazily on the first del
543a0a4
Most types are never deleted from, so the interface walk that finds IDictionary<K,V>.Remove or IList<T>.RemoveAt now runs on the first del instead of at class creation.
Martin-Molinero
Martin-Molinero approved these changes Sep 3, 2026
View reviewed changes
@jhonabreul
Bump version to 2.0.66
0115d6d
@jhonabreul
jhonabreul merged commit 56b3b6e into QuantConnect:master Sep 3, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@jhonabreul
jhonabreul deleted the bug-del-item-crash branch September 3, 2026 18:34
@jhonabreul jhonabreul mentioned this pull request Sep 3, 2026
Update QuantConnect.pythonnet to 2.0.66 QuantConnect/Lean#9772
Merged
5 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Martin-Molinero Martin-Molinero Martin-Molinero approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@jhonabreul @Martin-Molinero
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.