PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Cannot pickle unknown errors

Open guarin opened this issue 3 years ago • 0 comments

Overview

Hi! First a big thank you for your great work on pyav!

I just ran into a problem when pickling/unpickling pyav errors which can sometimes raise an exception.

Expected behavior

Pickling an error with a known error code succeeds:

import pickle
import av
pickle.loads(pickle.dumps(av.error.BSFNotFoundError(1179861752, '')))

Returns:

av.error.BSFNotFoundError(1179861752, '')

Actual behavior

Pickling an error with an unknown error code raises a KeyError:

pickle.loads(pickle.dumps(av.error.UndefinedError(0, '')))

Error:

KeyError                                  Traceback (most recent call last)
      1 import pickle
      2 import av
----> 3 pickle.loads(pickle.dumps(av.error.UndefinedError(0, '')))

File av/enum.pyx:132, in av.enum._unpickle()

File av/enum.pyx:60, in av.enum.EnumType.__getitem__()

KeyError: 'ERRORTYPE_0'

The original error in production happened with ERRORTYPE_5. Please let me know if anyone knows where the actual error might be coming from.

Investigation

The issue seems to be that the EnumType in av.error.EnumType contains only types for known error codes. Adding the unknown error with EnumType._create(...) fixes the issue.

Versions

PyAV v9.2.0
library configuration: --prefix=/opt/conda/envs/lightly --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1636205340875/_build_env/bin/x86_64-conda-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-demuxer=dash --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-vaapi --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-libvpx --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/home/conda/feedstock_root/build_artifacts/ffmpeg_1636205340875/_build_env/bin/pkg-config
library license: GPL version 3 or later
libavcodec     58.134.100
libavdevice    58. 13.100
libavfilter     7.110.100
libavformat    58. 76.100
libavutil      56. 70.100
libswresample   3.  9.100
libswscale      5.  9.100

guarin avatar Jun 02 '22 15:06 guarin