Skip to content

Commit 35a5e35

Browse files
Merge pull request #37 from AdCombo/revert_bad_resource_validation_commit
Revert bad resource validation commit
2 parents 3a597c8 + 01dfada commit 35a5e35

File tree

6 files changed

+3
-174
lines changed

6 files changed

+3
-174
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# The short X.Y version.
6464
version = "1.0"
6565
# The full version, including alpha/beta/rc tags.
66-
release = "1.0.4"
66+
release = "1.0.5"
6767

6868
# The language for content autogenerated by Sphinx. Refer to documentation
6969
# for a list of supported languages.

flask_combo_jsonapi/resource.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from flask_combo_jsonapi.schema import compute_schema, get_relationships, get_model_field
1818
from flask_combo_jsonapi.data_layers.base import BaseDataLayer
1919
from flask_combo_jsonapi.data_layers.alchemy import SqlalchemyDataLayer
20-
from flask_combo_jsonapi.utils import JSONEncoder, validate_model_init_params
20+
from flask_combo_jsonapi.utils import JSONEncoder
2121

2222

2323
class ResourceMeta(MethodViewType):
@@ -39,14 +39,6 @@ def __new__(cls, name, bases, d):
3939
data_layer_kwargs = d["data_layer"]
4040
rv._data_layer = data_layer_cls(data_layer_kwargs)
4141

42-
if "schema" in d and "model" in data_layer_kwargs:
43-
model = data_layer_kwargs["model"]
44-
schema_fields = [get_model_field(d["schema"], key) for key in d["schema"]._declared_fields.keys()]
45-
invalid_params = validate_model_init_params(model=model, params_names=schema_fields)
46-
if invalid_params:
47-
raise Exception(f"Construction of {name} failed. Schema '{d['schema'].__name__}' has "
48-
f"fields={invalid_params} are not declare in {model.__name__} init parameters")
49-
5042
rv.decorators = (check_headers,)
5143
if "decorators" in d:
5244
rv.decorators += d["decorators"]

flask_combo_jsonapi/utils.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import inspect
2-
31
import simplejson as json
42
from uuid import UUID
53
from datetime import datetime
@@ -19,30 +17,3 @@ def default(self, obj):
1917
elif isinstance(obj, UUID):
2018
return str(obj)
2119
return json.JSONEncoder.default(self, obj)
22-
23-
24-
def get_model_init_params_names(model):
25-
"""Retrieve all params of model init method
26-
27-
:param DeclarativeMeta model: an object from sqlalchemy
28-
:return tuple: list of init method fields names and boolean flag that init method has kwargs
29-
"""
30-
argnames, _, varkw = inspect.getfullargspec(model.__init__)[:3]
31-
if argnames:
32-
argnames.remove('self')
33-
return argnames, bool(varkw)
34-
35-
36-
def validate_model_init_params(model, params_names):
37-
"""Retrieve invalid params of model init method if it exists
38-
:param DeclarativeMeta model: an object from sqlalchemy
39-
:param list params_names: parameters names to check
40-
:return list: list of invalid fields or None
41-
"""
42-
init_args, has_kwargs = get_model_init_params_names(model)
43-
if has_kwargs:
44-
return
45-
46-
invalid_params = [name for name in params_names if name not in init_args]
47-
if invalid_params:
48-
return invalid_params

setup.py

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

4-
__version__ = "1.0.4"
4+
__version__ = "1.0.5"
55

66

77
requirements_filepath = os.path.join(os.path.dirname(__name__), "requirements.txt")

tests/test_resource.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/test_utils.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)