Skip to content

Conversation

@marcoep
Copy link

@marcoep marcoep commented Jan 7, 2026

I tried to delete a ModeSolverTask as part of my automation scripts. However, deletion failed with the following error message:

Cell In[10], line 90
     87         continue
     89 if time.time() - start_times[eidx] > eval_timeout_s:
---> 90     exp.mode_solver_task.delete()
     91     if retries[eidx] < eval_retries:
     92         print(f" Simulation {exp.param_hash} has timed out. Resubmitting...")

File ~/.conda/envs/tidy3d_py312/lib/python3.12/site-packages/tidy3d/web/api/mode.py:489, in ModeSolverTask.delete(self)
    487 """Delete the mode solver and its corresponding task from the server."""
    488 # Delete mode solver
--> 489 http.delete(f"{MODESOLVER_API}/{self.task_id}/{self.solver_id}")
    490 # Delete parent task
    491 http.delete(f"tidy3d/tasks/{self.task_id}")

File ~/.conda/envs/tidy3d_py312/lib/python3.12/site-packages/tidy3d/web/core/http_util.py:198, in http_interceptor.<locals>.wrapper(*args, **kwargs)
    195         log = get_logger()
    196         log.warning(warning)
--> 198 return result.get("data") if "data" in result else result

TypeError: argument of type 'bool' is not iterable

The last line (l198) triggering the error incorrectly assumes that result is an iterable. My suggested fix only checks for the existence of the "data" key if result is of type dict, otherwise simply returns result.


Note

Fixes response handling in http_interceptor to avoid assuming JSON is always a dict.

  • Only accesses result["data"] when result is a dict; otherwise returns the parsed JSON as-is
  • Preserves existing warning logging and behavior for dict responses

Written by Cursor Bugbot for commit b2a6047. This will update automatically on new commits. Configure here.

Greptile Summary

Fixed a TypeError in http_interceptor that occurred when API responses returned non-dict types (e.g., boolean values from DELETE operations). The fix adds an isinstance(result, dict) check before attempting dictionary operations like membership testing and key access.

  • Added type guard using isinstance() before checking for 'data' key in response
  • Prevents TypeError: argument of type 'bool' is not iterable when DELETE endpoints return boolean success values
  • Maintains backward compatibility with existing dict responses containing 'data' key
  • Minor style inconsistencies: mixed quote styles and trailing whitespace

Confidence Score: 4/5

  • This PR is safe to merge with only minor style improvements needed
  • The fix correctly addresses a real TypeError bug by adding proper type checking. The logic is sound and maintains backward compatibility. Score reduced by 1 point only due to minor style inconsistencies (mixed quotes and trailing whitespace) that should be cleaned up before merge.
  • No files require special attention - the change is straightforward and the logic is correct

Important Files Changed

Filename Overview
tidy3d/web/core/http_util.py Fixed TypeError when HTTP response returns non-dict types (e.g., boolean) by adding isinstance check before accessing dict members

Sequence Diagram

sequenceDiagram
    participant Client as API Client
    participant HTTP as http_interceptor
    participant API as Tidy3D API
    
    Client->>HTTP: http.delete(endpoint)
    HTTP->>API: DELETE request
    API-->>HTTP: 200 OK + JSON response
    
    alt Response has text
        HTTP->>HTTP: Parse JSON
        
        alt Result is dict
            HTTP->>HTTP: Check for warning
            opt Warning exists
                HTTP->>HTTP: Log warning
            end
            
            alt Has "data" key
                HTTP-->>Client: Return result["data"]
            else No "data" key
                HTTP-->>Client: Return result (entire dict)
            end
        else Result is not dict (e.g., boolean)
            Note over HTTP: NEW: Skip dict operations
            HTTP-->>Client: Return result directly
        end
    else Response has no text
        HTTP-->>Client: Return None
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (2)

  1. tidy3d/web/core/http_util.py, line 198-199 (link)

    style: mixed quote styles in same block - line 193 uses double quotes for "warning" while line 198 uses single quotes for 'data'

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

  2. tidy3d/web/core/http_util.py, line 200 (link)

    style: trailing whitespace on this line

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @marcoep, looks great!

@marcoep
Copy link
Author

marcoep commented Jan 7, 2026

@yaugenst-flex can you help me fixing the failing checks? Why should my branch name should include a Jira key?

@yaugenst-flex
Copy link
Collaborator

@yaugenst-flex can you help me fixing the failing checks? Why should my branch name should include a Jira key?

Mostly because we didn't account for external contributors in that CI check 😉 We'll get that sorted out, it shouldn't block your PR. The only thing that'd be helpful for you to do is if you could squash your two commits into a single one and use the conventional commit style for your commit message. In this case basically just prefix your commit message with fix: ...

@yaugenst-flex yaugenst-flex changed the title bugfix: http_interceptor fails if result is not of type dict bugfix: http_interceptor fails if result is not of type dict (FXC-4739) Jan 8, 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.

2 participants