Chaffelson/nipyapi

BundleTypeValues in ExtensionBundle are not matched by value, but by the Enum name

duhizjame opened this issue · 4 comments

  • Nipyapi version: 0.19
  • NiFi version: 1.19(but applicable to all versions)
  • NiFi-Registry version: 1.19
  • Python version: 3.11
  • Operating System: MacOS

Description

Right now the call:

bundles = nipyapi.registry.BundlesApi().get_bundles()

is throwing an exception:

  File "/Users/aleksandarmilosevic/Desktop/invoke.http/venv/lib/python3.11/site-packages/nipyapi/registry/models/extension_bundle.py", line 382, in bundle_type
    raise ValueError(
ValueError: Invalid value for `bundle_type` (nifi-nar), must be one of ['NIFI_NAR', 'MINIFI_CPP']

What I Did

This is the actual definition in the nifi-registry-core:

public class BundleTypeValues {

    public static final String NIFI_NAR_VALUE = "nifi-nar";
    public static final String MINIFI_CPP_VALUE = "minifi-cpp";

    public static final String ALL_VALUES = NIFI_NAR_VALUE + ", " + MINIFI_CPP_VALUE;
}

Changing the extension bundle bundle_type solves the issue:

    @bundle_type.setter
    def bundle_type(self, bundle_type):
        """
        Sets the bundle_type of this ExtensionBundle.
        The type of the extension bundle

        :param bundle_type: The bundle_type of this ExtensionBundle.
        :type: str
        """
        if bundle_type is None:
            raise ValueError("Invalid value for `bundle_type`, must not be `None`")
        # was allowed_values = ["NIFI_NAR", "MINIFI_CPP"]
        allowed_values = ["nifi-nar", "minifi-cpp"]
        if bundle_type not in allowed_values:
            raise ValueError(
                "Invalid value for `bundle_type` ({0}), must be one of {1}"
                .format(bundle_type, allowed_values)
            )

        self._bundle_type = bundle_type

Urgency

Not urgent, but a good fix for a CI/CD that my I am implementing.
I can open a PR to handle this if needed, so far I was fine with monkey patching
Although the documentation on the NiFi registry API is a bit misguiding as well, there is no mention of the actual values for the enum.

Hi @duhizjame this comes up occasionally string literals in the NiFi swagger spec - it was never originally written to be used to generate a client like this, so we sometimes run into these conversion issues.

The model code is templated here
I note in the swagger def that it is canonically CAPS.
I have a memory that this should not be all caps from a previous bug like this, we could check in with the NiFi dev community for an opinion?

Edit: Posted on Slack

Thanks for the fast response! @Chaffelson
I joined the slack channel, so I'll monitor if there is any progress as well. Until then, monkey patching will do the job 😄

There is an existing NiFi issue on this: NIFI-12302