Skip to content

[FIX] server_environment: Protect import - #670

Merged
pedrobaeza merged 1 commit into
OCA:9.0from
Tecnativa:9.0-server_environment-fix
Dec 23, 2016
Merged

pedrobaeza merged 1 commit into
OCA:9.0from
Tecnativa:9.0-server_environment-fix

Conversation

@pedrobaeza

Copy link
Copy Markdown
Member

Trying to fix the mess that this module merge has provoked.

Fast-tracking if all goes right.

@lasley

lasley commented Dec 23, 2016

Copy link
Copy Markdown
Contributor

Re #667

@lasley lasley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 pending CI 🍏

@tedsalmon

Copy link
Copy Markdown

Hey @pedrobaeza,

The Exception will still raise because you're only catching the ImportError. I actually fixed this earlier in this branch https://github.com/LasLabs/server-tools/blob/9.0-guard-server-environment-exceptions/server_environment/serv_config.py and came here to submit the PR :P

Thanks!

@tedsalmon tedsalmon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Made some suggestions based on my previous comment :)

)
if not system_base_config.get('running_env', False):
raise Exception(
"The parameter 'running_env' has not be set neither in base "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Though I know you didn't write this exception, It could use a little sprucing up. Might I suggest:

            "The parameter 'running_env' is not set in the base config file, "
            "option -c or in openerprc.\n"
            "We strongly discourage the use of an rc file and instead "
            "recommend you explicitly add the following options into your "
            "config:\n[options]\nrunning_env = [dev|prod]"

"please add a folder %s" % ck_path
)
if not system_base_config.get('running_env', False):
raise Exception(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EnvironmentError makes more sense than a plain Exception

ck_path = os.path.join(_dir, system_base_config['running_env'])

if not os.path.exists(ck_path):
raise Exception(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

EnvironmentError makes more sense than a plain Exception

_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
'0': False, 'no': False, 'false': False, 'off': False}

if not system_base_config.get('running_env', False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not move this logic (L39:L54) into _load_config() and then wrap the serv_config = _load_config() in a try/except for EnvironmentError?

@pedrobaeza

Copy link
Copy Markdown
Member Author

@t3ddftw, thanks for the suggestion, but as this is only a PR for fixing the error on branches with this module not installed, is out of bounds to refactor it, so I prefer to keep it as is, because I'm not even using it.

P.S.: cryptic login you have, hehe

@pedrobaeza

Copy link
Copy Markdown
Member Author

OK, fast-tracking as stated. Please make another PR for the suggestion you made.

@pedrobaeza
pedrobaeza merged commit fd2aed6 into OCA:9.0 Dec 23, 2016
@pedrobaeza
pedrobaeza deleted the 9.0-server_environment-fix branch December 23, 2016 21:50
@tedsalmon

Copy link
Copy Markdown

@pedrobaeza,

Yeah, we aren't using this either but similarly to you, we ran into issues deploying this repo. I'll submit another PR as you suggested as I don't like the fact that you can still run into an Exception if you have server_environment_files available but no running_env config option set :).

Haha yes, this has been my GitHub login for too long to give it up now.

Thanks!

SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (9.0)
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.

3 participants