Skip to content

add_session_metadata api is broken #641

@klimburg

Description

@klimburg

The add_session_metadata api results in a 500.

There are two separate issues in the implementation as it exists today. Session.metadata_objects does not exist but rather Session.metadata_items is the correct attribute and then the key doesnt get set. Its unclear whether add_session_metadata is intended to add one item at a time or if the metadata dict is intended to set multiple items one for each key. Depending on the intent either of the following implementation works.

One Item per call

@API
def add_session_metadata(id: int, key: str, metadata: Any):
    try:
        session = Session.query.filter(Session.id == id).one()
        session.metadata_items.append(
            SessionMetadata(key=key, metadata_item=metadata))
    except NoResultFound:
        abort(requests.codes.not_found)
    db.session.commit()

Multiple Items per call

@API
def add_session_metadata(id: int, metadata: dict):
    try:
        session = Session.query.filter(Session.id == id).one()
        for key, value in metadata.items():
            session.metadata_items.append(
                SessionMetadata(key=key, metadata_item=value))
    except NoResultFound:
        abort(requests.codes.not_found)
    db.session.commit()

Personally I prefer the multiple items per call approach.

Finally I suspect add_test_metadata has a similar issue but I havent tested it yet. Just looking at the source I believe it should be test.metadatas and not test.metadata_objects and similar with the missing key parameter to the TestMetadata constructor.

@vmalloc If i submit fixes will they be taken? It seems like development has really slowed down.

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