Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Custom command expects string type #809

Open
ghost opened this issue Aug 26, 2023 · 1 comment
Open

[bug] Custom command expects string type #809

ghost opened this issue Aug 26, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 26, 2023

The controller expects strings, but if you pass it a list, we get a TypeError.
For instance, if you define a custom command that has checkboxes like:

(
        'lockbands',
        {
            'label': 'Lock to Specific Bands',
            'schema': {
                'title': 'Lock Mobile Bands',
                'type': 'object',
                'properties': {
                    'bands': {
                        'type': 'array',
                        'title': 'Warning: Check that the bands you are locking to are actually available first or your device might not reconnect - Select Bands to Lock',
                        'items': {
                            'type': 'string',
                            'enum': [
                                '4G Band 1',
                                '4G Band 3',
                                '4G Band 5',
                                '4G Band 7',
                                '4G Band 8',
                                '4G Band 28',
                                '4G Band 40',
                            ]
                        },
                        'uniqueItems': True,
                        'minItems': 1
                    },
                    'modem_index': {
                        'type': 'string',
                        'title': 'Modem ID (leave blank for default)',
                    },
                },
                'required': ['bands'],
                'additionalProperties': False,
            },
            'callable': lockbands_command_callable,
        }
    ),

TypeError: sequence item 0: expected str instance, list found

There are a ton of ways to fix this, and I'm not sure if there are other architecture-level decisions that would limit the choices, but what I did is cast the argument to a string
On line 606 in openwisp_controller/connection/base/models.py
replace
return ', '.join(self.arguments)
with
return ', '.join(str(arg) for arg in self.arguments)

@nemesifier
Copy link
Member

So if my understanding is correct, right now we only allow simple string input values and allowing also lists would improve the solution?

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

No branches or pull requests

1 participant