Skip to content

Commit 76758d1

Browse files
committed
Fix a bug in BaseCollection.properties method
1 parent cef2fc0 commit 76758d1

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

arango/collections/base.py

+43-39
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ def _status(self, code):
102102
103103
:param code: the collection status code
104104
:type code: int
105-
:returns: the collection status text
106-
:rtype: str | unicode
105+
:returns: the collection status text or ``None``
106+
:rtype: str | unicode | None
107107
:raises arango.exceptions.CollectionBadStatusError: if the collection
108108
status code is unknown
109109
"""
110+
if code is None: # pragma: no cover
111+
return None
110112
try:
111113
return self.STATUSES[code]
112114
except KeyError:
@@ -217,10 +219,10 @@ def handler(res):
217219
def properties(self):
218220
"""Return the collection properties.
219221
220-
:returns: the collection properties
222+
:returns: The collection properties.
221223
:rtype: dict
222-
:raises arango.exceptions.CollectionPropertiesError: if the
223-
collection properties cannot be retrieved
224+
:raises arango.exceptions.CollectionPropertiesError: If the
225+
collection properties cannot be retrieved.
224226
"""
225227
request = Request(
226228
method='get',
@@ -230,24 +232,24 @@ def properties(self):
230232
def handler(res):
231233
if res.status_code not in HTTP_OK:
232234
raise CollectionPropertiesError(res)
233-
result = {
234-
'id': res.body['id'],
235-
'name': res.body['name'],
236-
'edge': res.body['type'] == 3,
237-
'sync': res.body['waitForSync'],
238-
'status': self._status(res.body['status']),
239-
'compact': res.body['doCompact'],
240-
'system': res.body['isSystem'],
241-
'volatile': res.body['isVolatile'],
242-
'journal_size': res.body['journalSize'],
243-
'keygen': res.body['keyOptions']['type'],
244-
'user_keys': res.body['keyOptions']['allowUserKeys'],
235+
236+
key_options = res.body.get('keyOptions', {})
237+
238+
return {
239+
'id': res.body.get('id'),
240+
'name': res.body.get('name'),
241+
'edge': res.body.get('type') == 3,
242+
'sync': res.body.get('waitForSync'),
243+
'status': self._status(res.body.get('status')),
244+
'compact': res.body.get('doCompact'),
245+
'system': res.body.get('isSystem'),
246+
'volatile': res.body.get('isVolatile'),
247+
'journal_size': res.body.get('journalSize'),
248+
'keygen': key_options.get('type'),
249+
'user_keys': key_options.get('allowUserKeys'),
250+
'key_increment': key_options.get('increment'),
251+
'key_offset': key_options.get('offset')
245252
}
246-
if 'increment' in res.body['keyOptions']:
247-
result['key_increment'] = res.body['keyOptions']['increment']
248-
if 'offset' in res.body['keyOptions']:
249-
result['key_offset'] = res.body['keyOptions']['offset']
250-
return result
251253

252254
return request, handler
253255

@@ -257,9 +259,9 @@ def configure(self, sync=None, journal_size=None):
257259
258260
Only *sync* and *journal_size* properties are configurable.
259261
260-
:param sync: wait for the operation to sync to disk
262+
:param sync: Wait for the operation to sync to disk.
261263
:type sync: bool
262-
:param journal_size: the journal size
264+
:param journal_size: The journal size.
263265
:type journal_size: int
264266
:returns: the new collection properties
265267
:rtype: dict
@@ -281,22 +283,24 @@ def configure(self, sync=None, journal_size=None):
281283
def handler(res):
282284
if res.status_code not in HTTP_OK:
283285
raise CollectionConfigureError(res)
284-
result = {
285-
'id': res.body['id'],
286-
'name': res.body['name'],
287-
'edge': res.body['type'] == 3,
288-
'sync': res.body['waitForSync'],
289-
'status': self._status(res.body['status']),
290-
'compact': res.body['doCompact'],
291-
'system': res.body['isSystem'],
292-
'volatile': res.body['isVolatile'],
293-
'journal_size': res.body['journalSize'],
294-
'keygen': res.body['keyOptions']['type'],
295-
'user_keys': res.body['keyOptions']['allowUserKeys'],
296-
'key_increment': res.body['keyOptions'].get('increment'),
297-
'key_offset': res.body['keyOptions'].get('offset')
286+
287+
key_options = res.body.get('keyOptions', {})
288+
289+
return {
290+
'id': res.body.get('id'),
291+
'name': res.body.get('name'),
292+
'edge': res.body.get('type') == 3,
293+
'sync': res.body.get('waitForSync'),
294+
'status': self._status(res.body.get('status')),
295+
'compact': res.body.get('doCompact'),
296+
'system': res.body.get('isSystem'),
297+
'volatile': res.body.get('isVolatile'),
298+
'journal_size': res.body.get('journalSize'),
299+
'keygen': key_options.get('type'),
300+
'user_keys': key_options.get('allowUserKeys'),
301+
'key_increment': key_options.get('increment'),
302+
'key_offset': key_options.get('offset')
298303
}
299-
return result
300304

301305
return request, handler
302306

arango/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '3.10.0'
1+
VERSION = '3.10.1'

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
packages=find_packages(),
1515
include_package_data=True,
1616
install_requires=['requests', 'six'],
17+
tests_require=['pytest'],
1718
classifiers=[
1819
'Intended Audience :: Developers',
1920
'Intended Audience :: End Users/Desktop',

tests/test_collection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def test_properties():
4444
assert isinstance(properties['journal_size'], int)
4545
assert properties['keygen'] in ('autoincrement', 'traditional')
4646
assert isinstance(properties['user_keys'], bool)
47-
if 'key_increment' in properties:
47+
if properties['key_increment'] is not None:
4848
assert isinstance(properties['key_increment'], int)
49-
if 'key_offset' in properties:
49+
if properties['key_offset'] is not None :
5050
assert isinstance(properties['key_offset'], int)
5151
with pytest.raises(CollectionBadStatusError):
5252
assert getattr(col, '_status')(10)

0 commit comments

Comments
 (0)