Skip to content

Reservations.to_json() fails with "TypeError: Object of type ReservationFlags is not JSON serializable" #423

Description

@behnle

We have the following reservation on our cluster:

[root@slurm-web restapi]# scontrol show res
ReservationName=comsol StartTime=2026-06-10T17:00:01 EndTime=2027-06-10T17:00:01 Duration=365-00:00:00
   Nodes=(null) NodeCnt=0 CoreCnt=0 Features=(null) PartitionName=compute Flags=ANY_NODES
   TRES=(null)
   AllowedPartitions=(null) QOS=(null)
   Users=(null) Groups=(null) Accounts=computeusers Licenses=COMSOLUSER:1 State=ACTIVE BurstBuffer=(null)
   MaxStartDelay=(null)

I can load the reservation, i can also convert it to a dictionary (notably, recursive=False and recursice=True behave identically):

>>> pprint.pp(pyslurm.Reservations().load().to_dict())
{'comsol': {'accounts': ['computeusers'],
            'burst_buffer': None,
            'cluster': 'cluster',
            'comment': None,
            'cpu_ids_by_node': {},
            'cpus': 0,
            'duration': 525600,
            'end_time': 1812639601,
            'features': [],
            'flags': <ReservationFlags.ANY_NODES: 256>,
            'groups': [],
            'is_active': True,
            'licenses': ['COMSOLUSER:1'],
            'max_start_delay': None,
            'name': 'comsol',
            'node_count': 0,
            'nodes': None,
            'partition': 'compute',
            'purge_time': 300,
            'reoccurrence': <ReservationReoccurrence.NO: 'NO'>,
            'start_time': 1781103601,
            'tres': {},
            'users': []}}
>>> pprint.pp(pyslurm.Reservations().load().to_dict(recursive=True))
{'comsol': {'accounts': ['computeusers'],
            'burst_buffer': None,
            'cluster': 'cluster',
            'comment': None,
            'cpu_ids_by_node': {},
            'cpus': 0,
            'duration': 525600,
            'end_time': 1812639601,
            'features': [],
            'flags': <ReservationFlags.ANY_NODES: 256>,
            'groups': [],
            'is_active': True,
            'licenses': ['COMSOLUSER:1'],
            'max_start_delay': None,
            'name': 'comsol',
            'node_count': 0,
            'nodes': None,
            'partition': 'compute',
            'purge_time': 300,
            'reoccurrence': <ReservationReoccurrence.NO: 'NO'>,
            'start_time': 1781103601,
            'tres': {},
            'users': []}}

but calling to_json() fails with the following error:

>>> pyslurm.Reservations().load().to_json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyslurm/xcollections.pyx", line 454, in pyslurm.xcollections.MultiClusterMap.to_json
  File "/usr/lib64/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ReservationFlags is not JSON serializable

This is probably not the intended behaviour. My suspicion is that there is code missing for the serialization of the ReservationFlags and ReservationReoccurrence objects.

Pyslurm version 25.11.2 under python3.9
SLURM 25.11.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions