Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use dict_to_json in httpdb (safer json.dumps) #629

Merged
merged 6 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ requests-mock~=1.8
# needed for system tests
matplotlib~=3.0
graphviz~=0.16.0
storey @ git+https://github.com/mlrun/storey.git ; python_version >= '3.7'
storey~=0.3; python_version >= '3.7'
2 changes: 1 addition & 1 deletion mlrun/datastore/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_store_artifact(self, url, project=""):
meta = db.read_artifact(key, tag=tag, iter=iteration, project=project)
if meta.get("kind", "") == "link":
# todo: support other link types (not just iter, move this to the db/api layer
meta = self._get_db().read_artifact(
meta = db.read_artifact(
parsed_url.path[1:],
tag=tag,
iter=meta.get("link_iteration", 0),
Expand Down
31 changes: 18 additions & 13 deletions mlrun/db/httpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import tempfile
import time
from datetime import datetime
Expand Down Expand Up @@ -354,7 +353,7 @@ def store_function(self, function, name, project="", tag=None, versioned=False):

error = f"store function {project}/{name}"
resp = self.api_call(
"POST", path, error, params=params, body=json.dumps(function)
"POST", path, error, params=params, body=dict_to_json(function)
)

# hash key optional to be backwards compatible to API v<0.4.10 in which it wasn't in the response
Expand Down Expand Up @@ -450,7 +449,7 @@ def create_schedule(self, project: str, schedule: schemas.ScheduleInput):
path = f"projects/{project}/schedules"

error_message = f"Failed creating schedule {project}/{schedule.name}"
self.api_call("POST", path, error_message, body=json.dumps(schedule.dict()))
self.api_call("POST", path, error_message, body=dict_to_json(schedule.dict()))

def update_schedule(
self, project: str, name: str, schedule: schemas.ScheduleUpdate
Expand All @@ -459,7 +458,7 @@ def update_schedule(
path = f"projects/{project}/schedules/{name}"

error_message = f"Failed updating schedule {project}/{name}"
self.api_call("PUT", path, error_message, body=json.dumps(schedule.dict()))
self.api_call("PUT", path, error_message, body=dict_to_json(schedule.dict()))

def get_schedule(
self, project: str, name: str, include_last_run: bool = False
Expand Down Expand Up @@ -751,7 +750,7 @@ def create_feature_set(
name = feature_set["metadata"]["name"]
error_message = f"Failed creating feature-set {project}/{name}"
resp = self.api_call(
"POST", path, error_message, params=params, body=json.dumps(feature_set),
"POST", path, error_message, params=params, body=dict_to_json(feature_set),
)
return resp.json()

Expand Down Expand Up @@ -851,7 +850,7 @@ def store_feature_set(
path = f"projects/{project}/feature-sets/{name}/references/{reference}"
error_message = f"Failed storing feature-set {project}/{name}"
resp = self.api_call(
"PUT", path, error_message, params=params, body=json.dumps(feature_set)
"PUT", path, error_message, params=params, body=dict_to_json(feature_set)
)
return resp.json()

Expand All @@ -875,7 +874,7 @@ def patch_feature_set(
"PATCH",
path,
error_message,
body=json.dumps(feature_set_update),
body=dict_to_json(feature_set_update),
headers=headers,
)

Expand Down Expand Up @@ -905,7 +904,11 @@ def create_feature_vector(
name = feature_vector["metadata"]["name"]
error_message = f"Failed creating feature-vector {project}/{name}"
resp = self.api_call(
"POST", path, error_message, params=params, body=json.dumps(feature_vector),
"POST",
path,
error_message,
params=params,
body=dict_to_json(feature_vector),
)
return resp.json()

Expand Down Expand Up @@ -965,7 +968,7 @@ def store_feature_vector(
path = f"projects/{project}/feature-vectors/{name}/references/{reference}"
error_message = f"Failed storing feature-vector {project}/{name}"
resp = self.api_call(
"PUT", path, error_message, params=params, body=json.dumps(feature_vector)
"PUT", path, error_message, params=params, body=dict_to_json(feature_vector)
)
return resp.json()

Expand All @@ -989,7 +992,7 @@ def patch_feature_vector(
"PATCH",
path,
error_message,
body=json.dumps(feature_vector_update),
body=dict_to_json(feature_vector_update),
headers=headers,
)

Expand Down Expand Up @@ -1065,7 +1068,9 @@ def store_project(
project = project.dict()
elif isinstance(project, mlrun.projects.MlrunProject):
project = project.to_dict()
response = self.api_call("PUT", path, error_message, body=json.dumps(project),)
response = self.api_call(
"PUT", path, error_message, body=dict_to_json(project),
)
return mlrun.projects.MlrunProject.from_dict(response.json())

def patch_project(
Expand All @@ -1080,7 +1085,7 @@ def patch_project(
headers = {schemas.HeaderNames.patch_mode: patch_mode}
error_message = f"Failed patching project {name}"
response = self.api_call(
"PATCH", path, error_message, body=json.dumps(project), headers=headers
"PATCH", path, error_message, body=dict_to_json(project), headers=headers
)
return mlrun.projects.MlrunProject.from_dict(response.json())

Expand All @@ -1094,7 +1099,7 @@ def create_project(
project = project.to_dict()
error_message = f"Failed creating project {project['metadata']['name']}"
response = self.api_call(
"POST", "projects", error_message, body=json.dumps(project),
"POST", "projects", error_message, body=dict_to_json(project),
)
return mlrun.projects.MlrunProject.from_dict(response.json())

Expand Down
10 changes: 0 additions & 10 deletions mlrun/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
from .utils import dict_to_yaml, get_in, dict_to_json, get_artifact_target


class ResourceSchema:
FeatureSet = "fset"
FeatureVector = "fvec"
Artifact = "store"

@classmethod
def is_resource(cls, kind):
return kind in [cls.Artifact, cls.FeatureSet, cls.FeatureVector]


class ModelObj:
_dict_fields = []

Expand Down