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

Report app dependency addition/removal to DataDog #35455

Merged
merged 12 commits into from
Dec 10, 2024
8 changes: 2 additions & 6 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4478,18 +4478,14 @@ def check_build_dependencies(self, new_build):
"""

def has_dependencies(build):
if isinstance(build, Application):
profile = build.profile
else:
profile = build.get('profile', {})

return bool(
profile.get('features', {}).get('dependencies')
build.profile.get('features', {}).get('dependencies')
)

new_build_has_dependencies = has_dependencies(new_build)

last_build = get_latest_build_doc(self.domain, self.id)
last_build = ApplicationBase.wrap(last_build) if last_build else None
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Not sure the difference but should this be cls.wrap? just like when the copy is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in instance method, so either self.__class__.wrap or ApplicationBase - I prefer the latter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will that impact if the function is called by inherited classes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if a subclass calls this method that would mean the ApplicationBase wrap method is still called and not the subclass's wrap method. I think this is OK, since we don't use anything except the profile attribute. But that is a good point, maybe it should take the subclass's own implementation of wrap?

Copy link
Contributor

Choose a reason for hiding this comment

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

ApplicationBase wrap method is still called and not the subclass's wrap method

Ya. We would be wrapping data for a different class on ApplicationBase which isn't ideal and would further lead to issues if the subclass adds more properties than ApplicationBase, which will get skipped leading to loss of data in case a save is performed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll update

Copy link
Contributor

Choose a reason for hiding this comment

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

You might check out wrap_app for this.

Copy link
Contributor Author

@Charl1996 Charl1996 Dec 9, 2024

Choose a reason for hiding this comment

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

@orangejenny What is the exact benefit of using wrap_app(last_build, self.__class__) instead of simply self.__class__.wrap(last_build)? I see the wrap_doc function have the get_correct_app_class addition, but that's only coming into play if I don't pass in the class name, which I will do in this instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably doesn't matter, then. I had just read the original code when making the suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

wrap_app looks like a nice catch all for different application and similar docs with a hard failure in case of unexpected scenarios. Definitely good to use when dealing with more complex code.
The class wrap seems safe here since we are passing a build explicitly.

last_build_has_dependencies = has_dependencies(last_build) if last_build else False

if not last_build_has_dependencies and new_build_has_dependencies:
Expand Down
Loading