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

Avoid refetching resource instances inside permissions framework #11542

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Oct 14, 2024

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description of Change

The methods in the permissions framework mostly expect to be provided with a resource id. Each method then fetches an instance from the database. If the caller already has a model instance, they can't provide it to avoid the refetch. This PR now allows the caller to do that.

Checklist

  • I targeted one of these branches:
    • dev/8.0.x (under development): features, bugfixes not covered below
    • dev/7.6.x (main support): regressions, crashing bugs, security issues, major bugs in new features
    • dev/6.2.x (extended support): major security issues, data loss issues
  • I added a changelog in arches/releases
  • I submitted a PR to arches-docs (if appropriate)
  • Unit tests pass locally with my changes
  • I added tests that prove my fix is effective or that my feature works
  • My test fails on the target branch

Ticket Background

resource_selects = [
q for q in queries if q["sql"].startswith('SELECT "resource_instances"')
]
self.assertEqual(len(resource_selects), 1, list(queries))
Copy link
Member Author

Choose a reason for hiding this comment

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

On the target branch, this fails like so:

======================================================================
FAIL: test_get (tests.views.api.test_permissions.InstancePermissionsAPITest.test_get)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jwalls/prj/arches/tests/views/api/test_permissions.py", line 33, in test_get
    self.assertEqual(len(resource_selects), 1, queries)
AssertionError: 3 != 1 : <django.test.utils.CaptureQueriesContext object at 0x1183095e0>

----------------------------------------------------------------------
Ran 1 test in 0.070s

Not the most high traffic endpoint, but an example of what this PR allows you to save in other cases (e.g. resource API)

Copy link
Contributor

@aarongundel aarongundel left a comment

Choose a reason for hiding this comment

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

This looks great to me. I'm a bit sad we can't target 7.6, but this'll help make a good case for an upgrade to 8.

@aarongundel aarongundel merged commit 8ed87f3 into dev/8.0.x Oct 18, 2024
6 checks passed
@aarongundel aarongundel deleted the jtw/fetch-resource-once branch October 18, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants