You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] ctx.triggered_id is not recognized as a dict #3968
I am defining multiple dynamic components and set their id like this:
id={"type": "entry", "index": id},
where the value of "index" gets changed depending on the component.
Now, when I want to use the id in a pattern-matching callback, I need to get the value of "index"to search a sqlite database. When I use
ctx.triggered_id.get("index"))
however, VS Code produces an error and says: ""get" is no known attribute of "None"". The call however correctly returns the value of "index"
The same problem happens with ctx.triggered_id["index"], although the error then says: "None" object is not subscriptable.
FYI: I translated the error messages from German to English. They could be slightly inaccurate, though their meaning should be correct
Expected behavior
I would expect it to see a dict as a possible type of triggered_id, so that there is no error shown.
Could you please include a minimal example to replicate the issue? Here is one that show that ctx.triggered_id can be None when the callback first runs:
HI @AnnMarieW, sorry, I should have done that from the beginning.
If I modify your example and put the .get function and ["index"] subscript behind ctx.triggered_id, then Pylance displays an error (reportOptionalMemberAccess for .get() and reportOptionalSubscript for ["index"]. I now see that if I test beforehand that ctx.triggered_idis not None, then the errors disappear. But since prevent_initial_call=True is set, only inputs with a dict as an id can trigger the callback, so the error is obsolete. But I can understand now that it can be argumented that – for type safety – there should be an additional check in place, independent from prevent_initial_call.
The error regarding ctx.outputs_grouping can also be circumvented by checking if isinstance(ctx.outputs_grouping, list), but since the outputs are statically written out as a dict, it would be nice if that could be somehow given over to Pylance. The issue Pylance reports is reportAttributeAccessIssue
I understand now that the type problems can be mitigated by extensive type checking. If this is too extensive to implement, then I fully understand, though it is cumbersome to have all these lines of typechecking in place, where the types are pretty much hardcoded.
Activity
ProfessorOwl commentedon Sep 1, 2026
The same problem also seems to exist with ctx.outputs_grouping.
I am defining the outputs like this:
This gives the following error when calling
ctx.outputs_grouping["entries"]The function
.get()is also not recognized as a valid function.Both
["entries"]and.get()work, nonethelessAnnMarieW commentedon Sep 1, 2026
@ProfessorOwl
Could you please include a minimal example to replicate the issue? Here is one that show that
ctx.triggered_idcan beNonewhen the callback first runs:ProfessorOwl commentedon Sep 2, 2026
HI @AnnMarieW, sorry, I should have done that from the beginning.
If I modify your example and put the .get function and ["index"] subscript behind
ctx.triggered_id, then Pylance displays an error (reportOptionalMemberAccessfor.get()andreportOptionalSubscriptfor["index"]. I now see that if I test beforehand thatctx.triggered_idis not None, then the errors disappear. But sinceprevent_initial_call=Trueis set, only inputs with a dict as an id can trigger the callback, so the error is obsolete. But I can understand now that it can be argumented that – for type safety – there should be an additional check in place, independent fromprevent_initial_call.The error regarding ctx.outputs_grouping can also be circumvented by checking
if isinstance(ctx.outputs_grouping, list), but since the outputs are statically written out as a dict, it would be nice if that could be somehow given over to Pylance. The issue Pylance reports isreportAttributeAccessIssueHere is a MWE:
I understand now that the type problems can be mitigated by extensive type checking. If this is too extensive to implement, then I fully understand, though it is cumbersome to have all these lines of typechecking in place, where the types are pretty much hardcoded.
camdecoster commentedon Sep 2, 2026
I'm inclined to leave the types as is, but I'll leave this open for now to see if anyone else would like to see a change.