Skip to content

fix(shared): Use the only available settings file #244

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 3 commits into from
Jun 18, 2025

Conversation

ElioDiNino
Copy link
Member

@ElioDiNino ElioDiNino commented Jun 17, 2025

Running manage.py commands currently fails because Django is looking for settings_prod.py which does not exist for shared.

@ElioDiNino ElioDiNino requested a review from matt-codecov June 17, 2025 20:48
@ElioDiNino ElioDiNino self-assigned this Jun 17, 2025
Copy link

seer-by-sentry bot commented Jun 17, 2025

Sentry detected 2 potential issues in your recent changes

Suspicion: The shared app's manage.py hardcodes test database settings, which might cause `OperationalError` when attempting database connections in production environments.
  • Description: The shared app's manage.py is configured to load shared.django_apps.settings_test regardless of the runtime environment (RUN_ENV). This settings file contains hardcoded database configurations pointing to test hosts like "postgres" and "timescale" with test credentials. When this code runs in a production environment where these test hosts and credentials do not exist, attempting to establish database connections will fail. For example, if RUN_ENV is "PRODUCTION", the code still loads settings_test.py, leading to connection attempts to non-production databases. This will result in a django.db.utils.OperationalError when database operations are attempted, such as during migrations or execution of management commands.
  • Code location: libs/shared/shared/django_apps/manage.py:10
  • Suggested fix: Create environment-specific settings files (e.g., settings_prod.py, settings_staging.py) for the shared app under shared.django_apps that use the standard configuration system (get_config) for database credentials and hosts, instead of hardcoding test settings.
Suspicion: Hardcoding `settings_test.py` in `libs/shared/shared/django_apps/manage.py` might cause database connection issues in non-test environments. The test settings contain hardcoded test hostnames that could trigger `OperationalError` if used outside the test setup.
  • Description: The code change hardcodes the DJANGO_SETTINGS_MODULE to shared.django_apps.settings_test when executing libs/shared/shared/django_apps/manage.py. The settings_test.py file contains hardcoded database configurations with test-specific hostnames like "postgres" and "timescale". These hardcoded values override the dynamic configuration loaded from db_settings.py. If libs/shared/shared/django_apps/manage.py is executed in a production or non-test environment where these test hostnames do not resolve, Django will attempt to connect to non-existent database servers. This will trigger an OperationalError (e.g., psycopg2.OperationalError or django.db.utils.OperationalError), leading to unexpected behavior or termination of the script.
  • Code location: libs/shared/shared/django_apps/settings_test.py:89~103
  • Suggested fix: Revert the hardcoding of DJANGO_SETTINGS_MODULE in libs/shared/shared/django_apps/manage.py and restore environment-aware settings loading, or ensure this script is strictly prevented from running in production environments.

Did you find this useful? React with a 👍 or 👎

Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.23%. Comparing base (d3d8f72) to head (236c182).
Report is 3 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
+ Coverage   94.21%   94.23%   +0.02%     
==========================================
  Files        1214     1215       +1     
  Lines       45022    45023       +1     
  Branches     1435     1435              
==========================================
+ Hits        42416    42427      +11     
+ Misses       2305     2295      -10     
  Partials      301      301              
Flag Coverage Δ
apiunit 96.47% <ø> (+<0.01%) ⬆️
sharedintegration 39.77% <50.00%> (+0.03%) ⬆️
sharedunit 88.23% <100.00%> (+0.07%) ⬆️
workerintegration 61.60% <ø> (ø)
workerunit 90.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codspeed-hq bot commented Jun 17, 2025

CodSpeed Performance Report

Merging #244 will not alter performance

Comparing ElioDiNino/shared-settings (236c182) with main (d3d8f72)

Summary

✅ 9 untouched benchmarks

@ElioDiNino ElioDiNino force-pushed the ElioDiNino/shared-settings branch from 54df06a to e3c9f01 Compare June 18, 2025 18:57
Running `manage.py` commands currently fails because the CLI is looking for `settings_prod.py` which does not exist for `shared`.
@ElioDiNino ElioDiNino force-pushed the ElioDiNino/shared-settings branch 2 times, most recently from 90739c1 to c63aeb5 Compare June 18, 2025 20:53
@ElioDiNino ElioDiNino force-pushed the ElioDiNino/shared-settings branch from c63aeb5 to 236c182 Compare June 18, 2025 21:04
@ElioDiNino ElioDiNino enabled auto-merge June 18, 2025 21:04
@ElioDiNino ElioDiNino added this pull request to the merge queue Jun 18, 2025
Merged via the queue into main with commit 5b88559 Jun 18, 2025
50 checks passed
@ElioDiNino ElioDiNino deleted the ElioDiNino/shared-settings branch June 18, 2025 21:20
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