FAI-CIVL / FAI-Airscore

AirScore - online paragliding / hanggliding GAP-based scoring software.
https://airscore.cc/
GNU General Public License v3.0
13 stars 17 forks source link

Don't expect the key external_admin_DB to exist. #180

Closed philderbeast closed 3 years ago

philderbeast commented 3 years ago

If I'm using the following .env file then please don't expect the key external_admin_DB to exist:

# .env
use_internal_admin_DB: yes # use internal table for admins and scorekeepers
internal_admin_DB: # if use_internal_admin_DB is yes the below settings are relevant
  allow_self_registration: yes # allows anyone to create a scorekeeper account
# .env.example
use_internal_admin_DB: yes # use internal table for admins and scorekeepers
internal_admin_DB: # if use_internal_admin_DB is yes the below settings are relevant
  allow_self_registration: yes # allows anyone to create a scorekeeper account
external_admin_DB: # if use_internal_admin_DB is no the below settings are relevant
  auth_url: https://auth_server  # auth server
  auth_type: rest  # rest, ajax, ...
File "/home/sid/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/app/autoapp.py", line 3, in <module>
from airscore.app import create_app
File "/app/airscore/app.py", line 7, in <module>
from airscore import commands, public, user, internal
File "/app/airscore/public/__init__.py", line 3, in <module>
Open an interactive python shell in this framefrom . import views  # noqa
File "/app/airscore/public/views.py", line 16, in <module>
from airscore.public.forms import LoginForm, ModifyParticipantForm, ResetPasswordForm, ResetPasswordRequestForm
File "/app/airscore/public/forms.py", line 5, in <module>
from airscore.user.models import User
File "/app/airscore/user/__init__.py", line 3, in <module>
from . import views  # noqa
File "/app/airscore/user/views.py", line 8, in <module>
import frontendUtils
File "/app/airscore/core/frontendUtils.py", line 1, in <module>
from db.tables import TblCompetition, TblTask, TblCompAuth, TblRegion, TblRegionWaypoint, TblTaskWaypoint
File "/app/airscore/core/db/tables.py", line 6, in <module>
from .conn import db_session
File "/app/airscore/core/db/conn.py", line 14, in <module>
from Defines import MYSQLHOST, DATABASE, MYSQLUSER, MYSQLPASSWORD
File "/app/airscore/core/Defines.py", line 94, in <module>
ADMIN_AUTH_URL = config['external_admin_DB']['auth_url']
KeyError: 'external_admin_DB'
kuaka commented 3 years ago

Both of these keys should always exist and both should be in defines.yaml and not .env

On Mon, 23 Nov 2020, 00:42 Phil de Joux, notifications@github.com wrote:

If I'm using the following .env file then please don't expect the key external_admin_DB to exist:

.envuse_internal_admin_DB: yes # use internal table for admins and scorekeepersinternal_admin_DB: # if use_internal_admin_DB is yes the below settings are relevant

allow_self_registration: yes # allows anyone to create a scorekeeper account

.env.exampleuse_internal_admin_DB: yes # use internal table for admins and scorekeepersinternal_admin_DB: # if use_internal_admin_DB is yes the below settings are relevant

allow_self_registration: yes # allows anyone to create a scorekeeper accountexternal_admin_DB: # if use_internal_admin_DB is no the below settings are relevant auth_url: https://auth_server # auth server auth_type: rest # rest, ajax, ...

File "/home/sid/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/app/autoapp.py", line 3, in from airscore.app import create_app File "/app/airscore/app.py", line 7, in from airscore import commands, public, user, internal File "/app/airscore/public/init.py", line 3, in Open an interactive python shell in this framefrom . import views # noqa File "/app/airscore/public/views.py", line 16, in from airscore.public.forms import LoginForm, ModifyParticipantForm, ResetPasswordForm, ResetPasswordRequestForm File "/app/airscore/public/forms.py", line 5, in from airscore.user.models import User File "/app/airscore/user/init.py", line 3, in from . import views # noqa File "/app/airscore/user/views.py", line 8, in import frontendUtils File "/app/airscore/core/frontendUtils.py", line 1, in from db.tables import TblCompetition, TblTask, TblCompAuth, TblRegion, TblRegionWaypoint, TblTaskWaypoint File "/app/airscore/core/db/tables.py", line 6, in from .conn import db_session File "/app/airscore/core/db/conn.py", line 14, in from Defines import MYSQLHOST, DATABASE, MYSQLUSER, MYSQLPASSWORD File "/app/airscore/core/Defines.py", line 94, in ADMIN_AUTH_URL = config['external_admin_DB']['auth_url'] KeyError: 'external_admin_DB'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FAI-CIVL/FAI-Airscore/issues/180, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETWEH6BSLYKBUFY4FFIICTSRD2LRANCNFSM4T6NQPWQ .

kuaka commented 3 years ago

just to be clear: you should not be deleting any keys from the defines.yaml even if they are not applicable. The comments say that they are not relevant but they are still expected.

kuaka commented 3 years ago

@philderbeast can this be closed?

philderbeast commented 3 years ago

Both of these keys should always exist and both should be in defines.yaml and not .env

Yes sorry, config file mixup.

you should not be deleting any keys from the defines.yaml even if they are not applicable

I don't think I deleted any keys. These files without .example suffix are not source controlled.

I'd be happier if the code was robust to missing keys in the config files.

kuaka commented 3 years ago

I don't think I deleted any keys. These files without .example suffix are not source controlled.

ok. in the example it has been there for months. I would prefer that the defines.yaml was in source control, but the issue is how can developers make changes to the config and make sure that these changes are not committed or overwritten on a pull. If you have an answer let us know. I know that there is a way to locally ignore files but have not been able to get it to work.

I'd be happier if the code was robust to missing keys in the config files.

what do you suggest? in a way the config is like code and I don't think we can expect to have a normal running app that is missing config. I think the only thing could be to make it fail gracefully or to assume defaults if a setting is missing (which could be hard to debug if someone thinks they have set a setting but there is a spelling error and the default is used)

kuaka commented 3 years ago

I think this should be closed. I don't think it is fair to expect the app to cope with a user deleting configs. In the end, the config is probably only going to be setup once on install and never touched again.