Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 426da16

Browse files
committed
Merge branch 'release-0.12.4'
2 parents 26c11f2 + fdbda42 commit 426da16

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed

examples/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Create the Flask application
1212
app = Flask(__name__)
1313
app.config['DEBUG'] = True
14+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1415

1516

1617
# Initialize SQLAlchemy

flask_rest_jsonapi/data_layers/alchemy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ def get_related_object(self, related_model, related_id_field, obj):
368368
.filter(getattr(related_model, related_id_field) == obj['id'])\
369369
.one()
370370
except NoResultFound:
371-
raise RelatedObjectNotFound('', "Could not find {}.{}={} object".format(related_model.__name__,
372-
related_id_field,
373-
obj['id']))
371+
raise RelatedObjectNotFound('', "{}.{}: {} not found".format(related_model.__name__,
372+
related_id_field,
373+
obj['id']))
374374

375375
return related_object
376376

flask_rest_jsonapi/data_layers/filtering/alchemy.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ def __init__(self, model, filter_, resource, schema):
3030

3131
def resolve(self):
3232
if 'or' not in self.filter_ and 'and' not in self.filter_ and 'not' not in self.filter_:
33-
if self.val is None and self.field is None:
34-
raise InvalidFilters("Can't find value or field in a filter")
35-
3633
value = self.value
3734

38-
if isinstance(self.val, dict):
39-
value = Node(self.related_model, self.val, self.resource, self.related_schema).resolve()
35+
if isinstance(value, dict):
36+
value = Node(self.related_model, value, self.resource, self.related_schema).resolve()
4037

4138
if '__' in self.filter_.get('name', ''):
4239
value = {self.filter_['name'].split('__')[1]: value}
@@ -83,22 +80,6 @@ def op(self):
8380
except KeyError:
8481
raise InvalidFilters("Can't find op of a filter")
8582

86-
@property
87-
def val(self):
88-
"""Return the val of the node
89-
90-
:return: the value to filter with
91-
"""
92-
return self.filter_.get('val')
93-
94-
@property
95-
def field(self):
96-
"""Return the field of the node
97-
98-
:return: the field to pick up value from to filter with
99-
"""
100-
return self.filter_.get('field')
101-
10283
@property
10384
def column(self):
10485
"""Get the column object
@@ -114,7 +95,7 @@ def column(self):
11495
try:
11596
return getattr(self.model, model_field)
11697
except AttributeError:
117-
raise InvalidFilters("{} has no attribute {} in a filter".format(self.model.__name__, model_field))
98+
raise InvalidFilters("{} has no attribute {}".format(self.model.__name__, model_field))
11899

119100
@property
120101
def operator(self):
@@ -128,21 +109,26 @@ def operator(self):
128109
if hasattr(self.column, op):
129110
return op
130111

131-
raise InvalidFilters("{} has no operator {} in a filter".format(self.column.key, self.op))
112+
raise InvalidFilters("{} has no operator {}".format(self.column.key, self.op))
132113

133114
@property
134115
def value(self):
135116
"""Get the value to filter on
136117
137118
:return: the value to filter on
138119
"""
139-
if self.field is not None:
120+
if self.filter_.get('field') is not None:
140121
try:
141-
return getattr(self.model, self.field)
122+
result = getattr(self.model, self.filter_['field'])
142123
except AttributeError:
143-
raise InvalidFilters("{} has no attribute {} in a filter".format(self.model.__name__, self.field))
124+
raise InvalidFilters("{} has no attribute {}".format(self.model.__name__, self.filter_['field']))
125+
else:
126+
return result
127+
else:
128+
if 'val' not in self.filter_:
129+
raise InvalidFilters("Can't find value or field in a filter")
144130

145-
return self.val
131+
return self.filter_['val']
146132

147133
@property
148134
def related_model(self):

flask_rest_jsonapi/resource.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,14 @@ def post(self, *args, **kwargs):
370370
includes.append(relationship_field)
371371
schema = compute_schema(self.schema, dict(), qs, includes)
372372

373-
status_code = 200 if updated is True else 204
373+
if updated is False:
374+
return '', 204
375+
374376
result = schema.dump(obj_).data
375377
if result.get('links', {}).get('self') is not None:
376378
result['links']['self'] = request.path
377379
self.after_post(result)
378-
return result, status_code
380+
return result, 200
379381

380382
@check_method_requirements
381383
def patch(self, *args, **kwargs):
@@ -416,12 +418,14 @@ def patch(self, *args, **kwargs):
416418
includes.append(relationship_field)
417419
schema = compute_schema(self.schema, dict(), qs, includes)
418420

419-
status_code = 200 if updated is True else 204
421+
if updated is False:
422+
return '', 204
423+
420424
result = schema.dump(obj_).data
421425
if result.get('links', {}).get('self') is not None:
422426
result['links']['self'] = request.path
423427
self.after_patch(result)
424-
return result, status_code
428+
return result, 200
425429

426430
@check_method_requirements
427431
def delete(self, *args, **kwargs):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33

4-
__version__ = '0.12.4'
4+
__version__ = '0.12.5'
55

66

77
setup(

0 commit comments

Comments
 (0)