Skip to content

Exceptions do not properly pickle and unpickle #587

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

Labels

area: api-compliancePython API behavior and typing: DB-API 2.0, exceptions, type stubs, new APIs.bugSomething isn't workinginADOtriage doneIssues that are triaged by dev team and are in investigation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions