Merge ~cjwatson/launchpad:testfix-productrelease-addreleasefile-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 96482331b7c1f6ef37627c57828b3d89ae65188f
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:testfix-productrelease-addreleasefile-bytes
Merge into: launchpad:master
Diff against target: 24 lines (+5/-1)
1 file modified
lib/lp/registry/model/productrelease.py (+5/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+379844@code.launchpad.net

Commit message

Fix productreleasefinder failures

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving trivial regression fix.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/model/productrelease.py b/lib/lp/registry/model/productrelease.py
2index 6dfc8b3..7ae8b4b 100644
3--- a/lib/lp/registry/model/productrelease.py
4+++ b/lib/lp/registry/model/productrelease.py
5@@ -14,6 +14,7 @@ from io import (
6 BytesIO,
7 )
8 import os
9+import sys
10
11 from sqlobject import (
12 ForeignKey,
13@@ -136,7 +137,10 @@ class ProductRelease(SQLBase):
14 file_size = len(file_or_data)
15 file_obj = BytesIO(file_or_data)
16 else:
17- assert isinstance(file_or_data, BufferedIOBase), (
18+ file_types = [BufferedIOBase]
19+ if sys.version_info[0] < 3:
20+ file_types.append(file)
21+ assert isinstance(file_or_data, tuple(file_types)), (
22 "file_or_data is not an expected type")
23 file_obj = file_or_data
24 start = file_obj.tell()

Subscribers

People subscribed via source and target branches

to status/vote changes: