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

Change the type of config data between client and gateway #1285

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client/quantum_serverless/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ def run( # pylint: disable=too-many-locals
"entrypoint": program.entrypoint,
"arguments": json.dumps(arguments or {}, cls=QiskitObjectsEncoder),
"dependencies": json.dumps(program.dependencies or []),
}
} # type: Dict[str, Any]
if config:
data["config"] = json.dumps(asdict(config))
data["config"] = asdict(config)
else:
data["config"] = "{}"
data["config"] = {}

response_data = safe_json_request(
request=lambda: requests.post(
Expand Down Expand Up @@ -525,11 +525,11 @@ def run_existing(
data = {
"title": title,
"arguments": json.dumps(arguments or {}, cls=QiskitObjectsEncoder),
}
} # type: Dict[str, Any]
if config:
data["config"] = json.dumps(asdict(config))
data["config"] = asdict(config)
else:
data["config"] = "{}"
data["config"] = {}

response_data = safe_json_request(
request=lambda: requests.post(
Expand Down
10 changes: 1 addition & 9 deletions gateway/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class RunExistingProgramSerializer(serializers.Serializer):

title = serializers.CharField(max_length=255)
arguments = serializers.CharField()
config = serializers.CharField()
config = serializers.DictField()
Tansito marked this conversation as resolved.
Show resolved Hide resolved

def retrieve_one_by_title(self, title, author):
"""
Expand All @@ -128,14 +128,6 @@ def retrieve_one_by_title(self, title, author):
.first()
)

def to_representation(self, instance):
"""
Transforms string `config` to JSON
"""
representation = super().to_representation(instance)
representation["config"] = json.loads(representation["config"])
return representation

def update(self, instance, validated_data):
pass

Expand Down
7 changes: 6 additions & 1 deletion gateway/tests/api/test_v1_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def test_run_existing(self):
"entrypoint": "program.py",
"arguments": "{}",
"dependencies": "[]",
"config": '{"workers": null, "min_workers": 1, "max_workers": 5, "auto_scaling": true}',
"config": {
"workers": None,
"min_workers": 1,
"max_workers": 5,
"auto_scaling": True,
},
},
format="json",
)
Expand Down
4 changes: 2 additions & 2 deletions gateway/tests/api/test_v1_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_run_existing_program_serializer_fails_at_validation(self):
serializer = RunExistingProgramSerializer(data=data)
self.assertFalse(serializer.is_valid())
errors = serializer.errors
self.assertListEqual(["arguments", "config"], list(errors.keys()))
self.assertListEqual(["arguments"], list(errors.keys()))

def test_run_existing_program_serializer_config_json(self):
assert_json = {
Expand All @@ -146,7 +146,7 @@ def test_run_existing_program_serializer_config_json(self):
data = {
"title": "Program",
"arguments": "{}",
"config": json.dumps(assert_json),
"config": assert_json,
}

serializer = RunExistingProgramSerializer(data=data)
Expand Down
Loading