Skip to content

Commit

Permalink
ref: match signatures of Manager post_save (#74954)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored and Christinarlong committed Jul 26, 2024
1 parent 98b301e commit 43d36be
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/sentry/db/models/manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def uncache_object(self, instance_id: int) -> None:
cache_key = self.__get_lookup_cache_key(**{pk_name: instance_id})
cache.delete(cache_key, version=self.cache_version)

def post_save(self, instance: M, **kwargs: Any) -> None: # type: ignore[misc] # python/mypy#6178
def post_save(self, *, instance: M, created: bool, **kwargs: object) -> None: # type: ignore[misc] # python/mypy#6178
"""
Triggered when a model bound to this manager is saved.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/discover/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __schedule_invalidate_project_config_transaction_commit(instance, trigger):
if RuleType.BOOST_KEY_TRANSACTIONS_RULE.value in enabled_biases:
schedule_invalidate_project_config(project_id=project.id, trigger=trigger)

def post_save(self, instance, **kwargs):
def post_save(self, *, instance: TeamKeyTransaction, created: bool, **kwargs: object) -> None:
# this hook may be called from model hooks during an
# open transaction. In that case, wait until the current transaction has
# been committed or rolled back to ensure we don't read stale data in the
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/options/organization_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def reload_cache(self, organization_id: int, update_reason: str) -> Mapping[str,
self._option_cache[cache_key] = result
return result

def post_save(self, instance: OrganizationOption, **kwargs: Any) -> None:
def post_save(self, *, instance: OrganizationOption, created: bool, **kwargs: object) -> None:
self.reload_cache(instance.organization_id, "organizationoption.post_save")

def post_delete(self, instance: OrganizationOption, **kwargs: Any) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/options/project_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def reload_cache(self, project_id: int, update_reason: str) -> Mapping[str, Any]
self._option_cache[cache_key] = result
return result

def post_save(self, instance: ProjectOption, **kwargs: Any) -> None:
def post_save(self, *, instance: ProjectOption, created: bool, **kwargs: object) -> None:
self.reload_cache(instance.project_id, "projectoption.post_save")

def post_delete(self, instance: ProjectOption, **kwargs: Any) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/sentry/models/options/project_template_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def reload_cache(self, project_template_id: int, update_reason: str) -> None:
cache.set(cache_key, result)
self._option_cache[cache_key] = result

def post_save(self, instance: ProjectTemplateOption, **kwargs: Any) -> None:
def post_save(
self, *, instance: ProjectTemplateOption, created: bool, **kwargs: object
) -> None:
self.reload_cache(instance.project_template_id, "projecttemplateoption.post_save")

def post_delete(self, instance: ProjectTemplateOption, **kwargs: Any) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/options/user_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_all_values(

return self._option_cache.get(metakey, {})

def post_save(self, instance: UserOption, **kwargs: Any) -> None:
def post_save(self, *, instance: UserOption, created: bool, **kwargs: object) -> None:
self.get_all_values(
instance.user, instance.project_id, instance.organization_id, force_reload=True
)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/projectkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProjectKeyStatus:


class ProjectKeyManager(BaseManager["ProjectKey"]):
def post_save(self, instance, **kwargs):
def post_save(self, *, instance: ProjectKey, created: bool, **kwargs: object) -> None:
schedule_invalidate_project_config(
public_key=instance.public_key, trigger="projectkey.post_save"
)
Expand Down
4 changes: 3 additions & 1 deletion src/sentry/models/releaseprojectenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def subscribe_project_to_alert_rule(
activator=activator,
)

def post_save(self, instance, created, **kwargs):
def post_save(
self, *, instance: ReleaseProjectEnvironment, created: bool, **kwargs: object
) -> None:
if created:
release = instance.release
project = instance.project
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/releases/release_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def subscribe_project_to_alert_rule(
activator=release.version,
)

def post_save(self, instance, created, **kwargs):
def post_save(self, *, instance: ReleaseProject, created: bool, **kwargs: object) -> None:
self._on_post(project=instance.project, trigger="releaseproject.post_save")
if created:
self.subscribe_project_to_alert_rule(
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_for_user(

return results

def post_save(self, instance, **kwargs):
def post_save(self, *, instance: Team, created: bool, **kwargs: object) -> None:
self.process_resource_change(instance, **kwargs)

def post_delete(self, instance, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/models/test_projectkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ def test_key_saved_projconfig_invalidated(inv_proj_config, default_project):

key = ProjectKey.objects.get(project=default_project)
manager = ProjectKeyManager()
manager.post_save(key)
manager.post_save(instance=key, created=False)

assert inv_proj_config.call_count == 1

0 comments on commit 43d36be

Please sign in to comment.