-
Notifications
You must be signed in to change notification settings - Fork 1
Release: fix 500s on /api/auth/user/info/ and /api/search/aimodel/ #191
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
14b882f
ci: generalize deploy-backend.yml to cover dev and prod
saqibmanan cd29cd1
Merge pull request #156 from CivicDataLab/ci/prod-deploy-pipeline-dev
saqibmanan 3ecac4e
fix: recover 3 real hotfixes made directly on prod-cds, never committed
saqibmanan 5b60872
docs: fix stale Keycloak domain and /auth prefix across SDK docs
saqibmanan b453612
Merge pull request #158 from CivicDataLab/fix/prod-hotfixes-from-host…
saqibmanan 53d6031
Merge pull request #160 from CivicDataLab/fix/stale-keycloak-domain-d…
saqibmanan 7c4542d
fix: register debug_toolbar in INSTALLED_APPS when DEBUG is on
saqibmanan bc6c85f
Merge pull request #162 from CivicDataLab/fix/debug-toolbar-installed…
saqibmanan ce7e5bc
fix: ci-deploy.sh no longer fights externally-owned dependency contai…
saqibmanan 326d8d2
Merge pull request #164 from CivicDataLab/fix/ci-deploy-dependency-co…
saqibmanan 2b8eb61
fix: attach backend/release to dataexchange_default network
saqibmanan c817bab
Merge pull request #166 from CivicDataLab/fix/backend-network-attachm…
saqibmanan 8f5ff05
fix: commit 46 missing api/authorization migrations, was gitignored
saqibmanan cced8c6
Merge pull request #168 from CivicDataLab/fix/missing-publication-mig…
saqibmanan 59d52a9
fix: point prod smoke tests at prod and skip provider-smoke there
saqibmanan 0a363ba
Merge pull request #176 from CivicDataLab/fix/prod-smoke-targets-prod…
saqibmanan 32d45d3
feat: two-stage dev smoke gate, readonly-only prod tests
saqibmanan 067a53c
feat: full-suite PR gate against dev for PRs into main
saqibmanan 3f78dc8
feat: run provider functional report-only while it is flaky against dev
saqibmanan c186cc8
Merge pull request #178 from CivicDataLab/feat/deploy-gating-model-dev
saqibmanan ac01ce4
fix: wait for every test before finalizing or rolling back
saqibmanan aa2c844
Merge pull request #180 from CivicDataLab/fix/finalize-waits-for-all-…
saqibmanan 53d925b
fix: pass KEYCLOAK_CLIENT_SECRET to the report-only provider job
saqibmanan 788b37d
fix: least-privilege permissions on pr-gate; pass Keycloak secret to …
saqibmanan f357491
Merge pull request #184 from CivicDataLab/fix/report-jobs-keycloak-se…
saqibmanan eaa5806
fix: require authentication on the user-info endpoint
saqibmanan cd2c2e1
fix: convert search hits to plain data before caching them
saqibmanan e494a29
test: cover the user-info 401 and the search-cache pickling
saqibmanan 2f98c7d
Merge pull request #187 from CivicDataLab/fix/user-info-auth-and-sear…
saqibmanan 3bca7a2
fix(tests): repair the syntax error that blocked test collection
saqibmanan 4a6ed7e
ci: run the Django test suite on push, PR and in the regression gate
saqibmanan eaf5a1c
Merge pull request #190 from CivicDataLab/fix/user-info-auth-and-sear…
saqibmanan 3bab067
Merge dev into main
saqibmanan 8a5e107
Potential fix for pull request finding 'CodeQL / Workflow does not co…
saqibmanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Django Tests | ||
|
|
||
| # The SDK workflows run a handful of tests with -p no:django, so nothing ever | ||
| # exercised the Django side: views, schema, permissions. This runs that suite. | ||
| on: | ||
| push: | ||
| branches: [dev, main] | ||
| pull_request: | ||
| branches: [dev, main] | ||
| workflow_call: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| django-tests: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
| cache: pip | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| # Not in requirements.txt, which covers the running service only. | ||
| pip install pytest pytest-django psycopg2-binary setuptools | ||
|
|
||
| - name: Prepare environment | ||
| run: | | ||
| cp .env.example .env | ||
| mkdir -p logs | ||
|
|
||
| # tests/object_types/charts and the dataset metadata tests were left | ||
| # behind by the chart consolidation and fail on main: see #189. | ||
| - name: Run tests | ||
| run: | | ||
| pytest tests/ \ | ||
| --ignore=tests/object_types/charts \ | ||
| --deselect tests/schema/test_dataset_schema.py::TestAddUpdateDatasetMetadata | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Regression tests for the two 500s on /api/auth/user/info/ and /api/search/aimodel/.""" | ||
|
|
||
| import pickle | ||
|
|
||
| import pytest | ||
| from elasticsearch_dsl import InnerDoc | ||
| from elasticsearch_dsl.utils import AttrDict, AttrList | ||
| from rest_framework.test import APIRequestFactory | ||
|
|
||
| from api.views.auth import UserInfoView | ||
| from api.views.paginated_elastic_view import as_plain_data | ||
|
|
||
|
|
||
| def nested_doc(**fields: object) -> InnerDoc: | ||
| """Build a nested doc the way elasticsearch_dsl does for a nested field. | ||
|
|
||
| The class is rebuilt per document type rather than being the module-level | ||
| InnerDoc, which is exactly what pickle refuses to serialize. | ||
| """ | ||
| cls = type("InnerDoc", (InnerDoc,), {}) | ||
| cls.__module__ = "elasticsearch_dsl.document" | ||
| doc = cls() | ||
| for name, value in fields.items(): | ||
| setattr(doc, name, value) | ||
| return doc | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| def test_user_info_rejects_anonymous_request() -> None: | ||
| """Anonymous callers get 401, not a 500 from reading .email off AnonymousUser. | ||
|
|
||
| The view is called directly: routing it through the test client hides the | ||
| bug, because the test settings drop the Keycloak middleware. | ||
| """ | ||
| request = APIRequestFactory().get("/api/auth/user/info/") | ||
| response = UserInfoView.as_view()(request) | ||
| assert response.status_code == 401 | ||
|
|
||
|
|
||
| def test_as_plain_data_makes_search_results_picklable() -> None: | ||
| """Nested hits must survive cache.set, which pickles the cached value.""" | ||
| result = { | ||
| "results": [ | ||
| { | ||
| "all_providers": AttrList([nested_doc(provider="GPT")]), | ||
| "name": AttrDict({"raw": "x"}), | ||
| } | ||
| ], | ||
| "total": 1, | ||
| } | ||
|
|
||
| plain = as_plain_data(result) | ||
| assert pickle.loads(pickle.dumps(plain)) == plain | ||
| assert plain["results"][0]["all_providers"] == [{"provider": "GPT"}] | ||
| assert plain["results"][0]["name"] == {"raw": "x"} | ||
| assert not _holds_elastic_objects(plain) | ||
|
|
||
|
|
||
| def _holds_elastic_objects(value: object) -> bool: | ||
| """The cache pickles what it is given, so no wrapper may survive anywhere.""" | ||
| if isinstance(value, (AttrDict, AttrList, InnerDoc)): | ||
| return True | ||
| if isinstance(value, dict): | ||
| return any(_holds_elastic_objects(item) for item in value.values()) | ||
| if isinstance(value, (list, tuple)): | ||
| return any(_holds_elastic_objects(item) for item in value) | ||
| return False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.