Skip to content

Fix the internal error that occurs when deleting a project not linked…#659

Merged
vincent-olivert-riera merged 3 commits intoline:masterfrom
hoangpn:bugfix/error_when_deleting_non-farm-project
Oct 16, 2025
Merged

Fix the internal error that occurs when deleting a project not linked…#659
vincent-olivert-riera merged 3 commits intoline:masterfrom
hoangpn:bugfix/error_when_deleting_non-farm-project

Conversation

@hoangpn
Copy link
Contributor

@hoangpn hoangpn commented Oct 15, 2025

… to any farm

After modifying the relationship between Farm and Project to one-to-one, directly accessing a project's farm using "project.farm" might trigger a RelatedObjectDoesNotExist exception, resulting in an internal error in Promgen. To prevent this, we must verify the existence of the farm every time before attempting to access it.

@hoangpn hoangpn force-pushed the bugfix/error_when_deleting_non-farm-project branch 3 times, most recently from fa98e21 to fd1c6f2 Compare October 15, 2025 10:49
Copy link
Contributor

@vincent-olivert-riera vincent-olivert-riera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment. Everything else looks good.

response = self.client.get(reverse(viewname, kwargs=params))
self.assertRoute(response, viewclass, status_code)

def test_delete_project_without_farm(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the addition of the test in a separate commit (remember to also move the models import you have added for it).

… to any farm

After modifying the relationship between Farm and Project to one-to-one, directly
accessing a project's farm using "project.farm" might trigger a RelatedObjectDoesNotExist
exception, resulting in an internal error in Promgen. To prevent this, we must verify
the existence of the farm every time before attempting to access it.
In the past, an error occurred when we forgot to check for the existence of a farm
before attempting to access it at the time the delete_project signal was triggered.
This caused the project deletion action to throw a RelatedObjectDoesNotExist exception
when it tried to access the farm of the project being deleted. As a result, the deletion
of the project or its parent service failed, and Promgen Web displayed an Internal Error.

We have added a self-test for this case to ensure that the bug has been fixed and
will always be checked in the future.
Currently, we are checking the existence of a project's farm before accessing it using
this syntax:
```
getattr(project, "farm", None) is not None
```

This can be shortened to:
```
hasattr(project, "farm")
```

We have replaced all instances of the original syntax with the new one.
@hoangpn hoangpn force-pushed the bugfix/error_when_deleting_non-farm-project branch from fd1c6f2 to e4f3dd5 Compare October 15, 2025 11:25
@vincent-olivert-riera vincent-olivert-riera merged commit 7549106 into line:master Oct 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants