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

Fixed crash when unknown fields are present JSON config #103

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all 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
11 changes: 6 additions & 5 deletions src/AMSWorkflow/ams/rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
import functools
import logging
import inspect
import ssl
import struct
import traceback
Expand Down Expand Up @@ -911,8 +912,6 @@ class AMSRMQConfiguration:
"""
service_port: int
service_host: str
rabbitmq_erlang_cookie: str
rabbitmq_name: str
rabbitmq_password: str
rabbitmq_user: str
rabbitmq_vhost: str
Expand All @@ -936,16 +935,18 @@ def from_json(cls, json_file):
data = json.load(fd)
data = {key.replace("-", "_"): value for key, value in data.items()}

return cls(**data)
# Filter out extra fields not accepted by this class
return cls(**{
k: v for k, v in data.items()
if k in inspect.signature(cls).parameters
})

def to_dict(self, AMSlib=False):
assert AMSlib, "AMSRMQConfiguration cannot convert class to non amslib dictionary"
if AMSlib:
return {
"service-port": self.service_port,
"service-host": self.service_host,
"rabbitmq-erlang-cookie": self.rabbitmq_erlang_cookie,
"rabbitmq-name": self.rabbitmq_name,
"rabbitmq-password": self.rabbitmq_password,
"rabbitmq-user": self.rabbitmq_user,
"rabbitmq-vhost": self.rabbitmq_vhost,
Expand Down