Skip to content

Fix TemplateSyntaxError pickling#1117

Merged
davidism merged 1 commit intopallets:masterfrom
andrewrabert:fix_exc_pickle
Jan 8, 2020
Merged

Fix TemplateSyntaxError pickling#1117
davidism merged 1 commit intopallets:masterfrom
andrewrabert:fix_exc_pickle

Conversation

@andrewrabert
Copy link
Copy Markdown
Contributor

@andrewrabert andrewrabert commented Dec 13, 2019

Implement __reduce__ to fix pickling of TemplateSyntaxError

New test output without the fix (Python 3.8):

________________________________________ TestDebug.test_pickleable_syntax_error _________________________________________

self = <test_debug.TestDebug object at 0x109740490>, fs_env = <jinja2.environment.Environment object at 0x1097400a0>

    def test_pickleable_syntax_error(self, fs_env):
        exc = TemplateSyntaxError('wtf', 42)
        pickled_exc = pickle.dumps(exc)
>       unpickled_exc = pickle.loads(pickled_exc)
E       TypeError: __init__() missing 1 required positional argument: 'lineno'

test_debug.py:78: TypeError

@davidism
Copy link
Copy Markdown
Member

davidism commented Dec 14, 2019

Interesting. Seems like it would be better to address why lineno isn't getting pickled/unpickled.

@andrewrabert
Copy link
Copy Markdown
Contributor Author

@andrewrabert
Copy link
Copy Markdown
Contributor Author

@davidism Changed the fix to only override __reduce__. No other changes to the exception.

@davidism davidism added this to the 2.11.0 milestone Jan 8, 2020
@davidism davidism merged commit 8342180 into pallets:master Jan 8, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants