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

Handle NoneType with graceful exception #33

Open
thclark opened this issue Nov 15, 2022 · 0 comments
Open

Handle NoneType with graceful exception #33

thclark opened this issue Nov 15, 2022 · 0 comments
Assignees
Labels
backend Related to the back end bug Unintended behaviour in any area of the app

Comments

@thclark
Copy link
Contributor

thclark commented Nov 15, 2022

Bug report

About me

If you're new to the twined ecosystem, and you don't mind, it'd be great to hear a little bit of the wider context about
you and what you're working on, so we can understand how best to help.

What is the current behavior?

If self.get_service_revision() is None in the following code, we get an error...

    def ask(self, save=True):
        """Ask a question to a service_revision.

        :param boolean save: If true, this question will be saved in order to update the 'asked' time.
        """

        service_revision = self.get_service_revision()
        subscription, push_url = service_revision.ask(
            question_id=self.id,
            input_values=self.get_input_values(),
            input_manifest=self.get_input_manifest(),
        )

The error is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django_gcp/tasks/tasks.py", line 116, in execute
    return self.run(**task_kwargs), 200
  File "/workspace/server/example/tasks.py", line 44, in run
    raise e
  File "/workspace/server/example/tasks.py", line 40, in run
    question.ask()
  File "/workspace/server/example/models.py", line 129, in ask
    subscription, push_url, service_revision = super().ask(save=False)
  File "/usr/local/lib/python3.9/site-packages/django_twined/models/questions.py", line 82, in ask
    subscription, push_url = service_revision.ask(
AttributeError: 'NoneType' object has no attribute 'ask'

What is the expected behavior?

It's a mistake to send a NoneType through to here, but could happen commonly, so a ValueError should be raised if the service_revision is not a valid class instance.

@thclark thclark self-assigned this Nov 15, 2022
@thclark thclark added backend Related to the back end bug Unintended behaviour in any area of the app labels Nov 15, 2022
@thclark thclark moved this to Priority 1 (Low) in Octue Board Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to the back end bug Unintended behaviour in any area of the app
Projects
Status: Priority 1 (Low)
Development

No branches or pull requests

1 participant