[Django] #27184: django test client bug when use TemporaryFile in Mac

41 views
Skip to first unread message

Django

unread,
Sep 6, 2016, 2:36:56 AM9/6/16
to django-...@googlegroups.com
#27184: django test client bug when use TemporaryFile in Mac
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
joonsikjang |
Type: Bug | Status: new
Component: Testing | Version: 1.9
framework | Keywords: test TemporaryFile django client
Severity: Normal | file upload
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
below code is file upload test method
This code was generated error message when I test only in Mac.
This code was ok when I test in Windows 10.
if I change TemporaryFile to NamedTemporaryFile, then It work correctly.


{{{
def test_ChunkedSampleFile(self):
"""
ChunkedSampleFileList, ChunkedSampleFileDetail View Test
"""
with TemporaryFile() as test_file:
for count in range(100000):
test_file.write(('test_data %s' % count).encode())
test_file.seek(0)
hash_md5 = hashlib.md5()
for chunk in iter(lambda: test_file.read(4096), b""):
hash_md5.update(chunk)
etag = hash_md5.hexdigest()
test_file.seek(0)

#post
response = self.client.post('%s/chunked_sample_files' %
URL_PREFIX,
data={'file': test_file, 'name': 'test.vcf',
'sample_file_meta':
self.sample_file_meta_id,
'file_seq': 1, 'etag': etag},
**{AUTH_TOKEN_HEADER_NAME: 'Token %s' %
self.testuserfastqc1_token} )
self.assertEqual(response.status_code,
status.HTTP_201_CREATED, response.content)
file_id = response.json()['id']
}}}

Error Message

ERROR: test_ChunkedSampleFile (analysis_files.tests.AnalysisFilesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/Users/joonsik/git/ngenebio_webapi/ngenebio_webapi/analysis_files/tests.py",
line 174, in test_ChunkedSampleFile
**{AUTH_TOKEN_HEADER_NAME: 'Token %s' % self.testuserfastqc1_token} )
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 515, in post
secure=secure, **extra)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 311, in post
post_data = self._encode_data(data, content_type)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 275, in _encode_data
return encode_multipart(BOUNDARY, data)
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 171, in encode_multipart
lines.extend(encode_file(boundary, key, value))
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/site-
packages/django/test/client.py", line 200, in encode_file
filename = os.path.basename(file.name) if hasattr(file, 'name') else
''
File "/Users/joonsik/venv_ngenebio_webapi/lib/python3.4/posixpath.py",
line 139, in basename
i = p.rfind(sep) + 1
AttributeError: 'int' object has no attribute 'rfind'

--
Ticket URL: <https://code.djangoproject.com/ticket/27184>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 6, 2016, 9:16:12 AM9/6/16
to django-...@googlegroups.com
#27184: django test client bug when use TemporaryFile in Mac
-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.9
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage:
django client file upload | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

New description:

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:1>

Django

unread,
Sep 6, 2016, 11:05:44 AM9/6/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix

-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: nobody
Type: Bug | Status: new

Component: Testing framework | Version: 1.9
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Accepted
django client file upload |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

I'm not sure if this should/can work, but if not, it would be nice to have
a friendlier message rather than a crash.

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:2>

Django

unread,
Sep 6, 2016, 11:53:47 AM9/6/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master

Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Accepted
django client file upload |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* version: 1.9 => master
* easy: 0 => 1


Comment:

This should be relatively easy to fix by testing the type of file.name.

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:3>

Django

unread,
Sep 11, 2016, 5:30:30 AM9/11/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: thomas-
| scrace
Type: Bug | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Accepted
django client file upload |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by thomas-scrace):

* owner: nobody => thomas-scrace
* status: new => assigned


Comment:

Fixed with https://github.com/django/django/pull/7230

This is my first django contribution. I've tried to follow the guidelines,
but please let me know if anything is wrong!

Thanks,
Tom

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:4>

Django

unread,
Sep 12, 2016, 3:20:26 AM9/12/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: thomas-
| scrace
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Accepted
django client file upload |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: 0 => 1


Comment:

Thanks! Comments added in the PR. Uncheck `patch needs improvement` after
you update the patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:5>

Django

unread,
Sep 12, 2016, 10:14:43 AM9/12/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: joonsikjang | Owner: thomas-
| scrace
Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Accepted
django client file upload |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:6>

Django

unread,
Nov 5, 2016, 12:55:06 PM11/5/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: Joonsik,Jang | Owner: Thomas
| Scrace

Type: Bug | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test TemporaryFile | Triage Stage: Ready for
django client file upload | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Federico Capoano):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


Comment:

Improved patch is available at https://github.com/django/django/pull/7230
and should be ready to be merged.

Federico

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:7>

Django

unread,
Nov 9, 2016, 5:54:58 AM11/9/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: Joonsik,Jang | Owner: Thomas
| Scrace
Type: Bug | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: test TemporaryFile | Triage Stage: Ready for
django client file upload | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"5549e89b847beb89e8c8b85b6fd6924028d991c3" 5549e89b]:
{{{
#!CommitTicketReference repository=""
revision="5549e89b847beb89e8c8b85b6fd6924028d991c3"
Fixed #27184 -- Allowed uploading TemporaryFile with the test client.

Thanks Federico Capoano for finishing the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:8>

Django

unread,
Dec 12, 2016, 12:42:09 PM12/12/16
to django-...@googlegroups.com
#27184: Test client crashes when uploading TemporaryFile on Unix
-------------------------------------+-------------------------------------
Reporter: Joonsik,Jang | Owner: Thomas
| Scrace
Type: Bug | Status: closed
Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed
Keywords: test TemporaryFile | Triage Stage: Ready for
django client file upload | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8db6a6c0a1c73bf08e71e00d4ab8c4af3c5f0cb8" 8db6a6c]:
{{{
#!CommitTicketReference repository=""
revision="8db6a6c0a1c73bf08e71e00d4ab8c4af3c5f0cb8"
Refs #27184 -- Fixed unclosed file ResourceWarning in test_client test.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27184#comment:9>

Reply all
Reply to author
Forward
0 new messages