Skip to content

Exceptions do not properly pickle and unpickle #587

@amachanic

Description

@amachanic

Describe the bug

If an exception generated by mssql-python is pickled, the following error will occur on unpickle:
[error].__init__() missing 1 required positional argument: 'ddbc_error'

This causes issues when using e.g. multiprocessing and attempting to marshal errors back to a central process.

To reproduce

import mssql_python, pickle

conn = mssql_python.connect("conn_string_here")
cur = conn.cursor()
try:
    cur.execute('insert into fake_tbl values (123)')
except Exception as e:
    d = pickle.dumps(e)

ex = pickle.loads(d)

Expected behavior

The pickled exception should cleanly unpickle, and then I should be able to treat it just like any other exception object.

Further technical details

Python version: 3.12.3
SQL Server version: N/A
Operating system: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage neededFor new issues, not triaged yet.

    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