Skip to content

UnboundLocalError occurs when MySQLResult fails to initialize due to SystemExit exception #1173

@palm002

Description

@palm002

Describe the bug
We have a service that makes calls to the database and over HTTP via workers. These are managed by kubernetes deployment resources.
These kubernetes pods that contain our workers get killed at random times for certain & specific reasons and we expect it to happen, so all our tasks are idempotent.
Due to a worker getting killed at a specific point we receive a SystemExit and observed an issue where the MySQLResult fails to initialise while a query was being executed and we end up with a UnboundLocalError

To Reproduce
Complete steps to reproduce the behavior:
Hard to reproduce as this is an edge case but the following code should prove that the specific scenario would cause an UnboundLocalError exception to occur. The following code is analogous to the method linked above.

Code:

class BadClass:
  def __init__(self) -> None:
    self.x = 1
    raise SystemExit


def boom():
  try:
    b = BadClass()
  except:
    print("Caught exception")
    b.x = 2
    print("raising")
    raise

boom()

image

Expected behavior
SystemExit should bubble up without causing UnboundLocalError exception to occur

Environment

  • OS: Linux
  • Server and version: MySQL 5.7.12-log
  • PyMySQL version: 1.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions