launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24381
[Merge] ~cjwatson/launchpad:testfix-productrelease-addreleasefile-bytes into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:testfix-productrelease-addreleasefile-bytes into launchpad:master.
Commit message:
Fix productreleasefinder failures
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/379844
productreleasefinder passes a tempfile.TemporaryFile instance down to ProductRelease.addReleaseFile, which on Python 2 is an instance of file but not an instance of io.BufferedIOBase. Tolerate this situation.
Regression caused by https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/379650.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:testfix-productrelease-addreleasefile-bytes into launchpad:master.
diff --git a/lib/lp/registry/model/productrelease.py b/lib/lp/registry/model/productrelease.py
index 6dfc8b3..7ae8b4b 100644
--- a/lib/lp/registry/model/productrelease.py
+++ b/lib/lp/registry/model/productrelease.py
@@ -14,6 +14,7 @@ from io import (
BytesIO,
)
import os
+import sys
from sqlobject import (
ForeignKey,
@@ -136,7 +137,10 @@ class ProductRelease(SQLBase):
file_size = len(file_or_data)
file_obj = BytesIO(file_or_data)
else:
- assert isinstance(file_or_data, BufferedIOBase), (
+ file_types = [BufferedIOBase]
+ if sys.version_info[0] < 3:
+ file_types.append(file)
+ assert isinstance(file_or_data, tuple(file_types)), (
"file_or_data is not an expected type")
file_obj = file_or_data
start = file_obj.tell()