Skip to content

Hook evaluation specification clarity #164

@tcarrio

Description

@tcarrio

This is in reference to the hooks evaluation order in Requirement 4.4.2. This reads:

Hooks MUST be evaluated in the following order:

  • before: API, Client, Invocation, Provider
  • after: Provider, Invocation, Client, API
  • error (if applicable): Provider, Invocation, Client, API
  • finally: Provider, Invocation, Client, API

Currently this is implemented differently between the Python and JavaScript SDKs, but neither is technically wrong based on the loose specification.

The JS SDK generates the before list of hooks, then reverses it for the after, error, and finally. This appeases the overall ordering of hook executions as listed above. Hence, the before is [...API, ...Client, ...Invocation, ...Provider]. The after is [...API, ...Client, ...Invocation, ...Provider].reverse(). So the after hooks will have all of the Provider hooks execute before the Invocation hooks, those before the Client hooks, and those before the API hooks.

The Python SDK generates the before list of hooks and the after/error/finally list of hooks by spreading them in their own declarations. So, before is API + Client + Invocation + Provider and the after is Provider + Invocation + Client + API. So the after hooks satisfy the same as mentioned above for the JS SDK.

The issue here is that the overall hook execution order would vary if any of these hooks have more than one entry. For example:

API = [A, B]
Client = [C, D]
Invocation = [E, F]
Provider = [G, H]

# `before` list
before_hooks = API + Client + Invocation + Provider

# spreading directly (like Python)
list1 = Provider + Invocation + Client + API
# results in [G, H, E, F, C, D, A, B]

# reversing the before list (like JavaScript)
list2 = before_hooks[:]
list2.reverse()
# results in [H, G, F, E, D, C, B, A]

This detail should be clear from the specification so there is not any discrepancy between implementations of the API.

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