Skip to content

Table generation context is passed as double-encoded JSON #77

Closed
@nickovs

Description

@nickovs

The context passed to table plugins' generate() methods is a JSON encoding of a JSON encoding of the data that the plugin actually cares about. If you want to access the actual context data structure then you need to use something like:

context = json.loads(json.loads(context))

While this issue has been in the code for at least six years, it's pretty clear from the source that this was not the original intention and is in fact a bug. Lines 41-43 of table_plugin.py read:

            ctx = {}
            if "context" in context:
                ctx = json.dumps(context["context"])

The underlying Thrift call context includes the table generation context as a string which contains the JSON-encoded details. The original author sets up a dictionary to pass to the generation function, then checks to see if a context was provided and, if present, replaces this with the JSON string encoding of the already-encoded context. It would make vastly more sense, and also be vastly more convenient for the user, to decode the context string value into another dictionary instead and thus for this to read:

                ctx = json.loads(context["context"])

This is almost certainly what the author intended and the current state is a typo. Hopefully this can still be fixed.

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