Skip to content

fix (datafile-parsing): Prevent newer versions datafile #141

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 6 commits into from
Sep 11, 2018

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Aug 30, 2018

No description provided.

@oakbani oakbani requested a review from mikeproeng37 August 30, 2018 14:50
@coveralls
Copy link

coveralls commented Aug 30, 2018

Coverage Status

Coverage increased (+0.02%) to 99.662% when pulling e6e94fc on oakbani/prevent-newer-datafile into f3e395a on master.



class DatafileVersions(object):
V1 = '1'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer needed

@@ -125,16 +145,41 @@ class InvalidErrorHandler(object):
def test_init__v1_datafile__logs_error(self):
""" Test that v1 datafile logs error on init. """

self.config_dict['version'] = project_config.V1_CONFIG_VERSION
self.config_dict['version'] = enums.DatafileVersions.V1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get rid of this test case as it tests the exact same thing as the one below

# We actually want to log this error to stderr, so make sure the logger
# has a handler capable of doing that.
self.logger.error(enums.Errors.UNSUPPORTED_DATAFILE_VERSION)
self.logger = _logging.reset_logger(self.logger_name)
self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('datafile'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check the type of the exception, and if it's exceptions.UnsupportedDatafileVersionException, then we log differently? I'd like that better than having two except clauses here.

Also, we should pass the exception to the error_handler instance


self.config_dict['version'] = project_config.V1_CONFIG_VERSION
self.config_dict['version'] = '5'
Copy link
Contributor

Choose a reason for hiding this comment

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

Please create a mock unsupported datafile and load into this test case.

# limitations under the License.


class InvalidAttributeException(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Can you arrange all these classes alphabetically.

@@ -65,3 +64,9 @@ class ControlAttributes(object):
BOT_FILTERING = '$opt_bot_filtering'
BUCKETING_ID = '$opt_bucketing_id'
USER_AGENT = '$opt_user_agent'


class DatafileVersions(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Lets arrange classes in this file alphabetically.

@@ -63,20 +63,22 @@ def __init__(self,

try:
self.config = project_config.ProjectConfig(datafile, self.logger, self.error_handler)
except:

Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Unnecessary newline.

# We actually want to log this error to stderr, so make sure the logger
# has a handler capable of doing that.
self.logger.error(enums.Errors.UNSUPPORTED_DATAFILE_VERSION)
if type(error) is exceptions.UnsupportedDatafileVersionException:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend instead of doing this having multiple except clauses

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I actually asked them to combine the multiple except clauses because the only thing that differs is the messaging. Otherwise we'd be duplicating (just 1 thing right now) the part where we pass the error to the handler.

Copy link
Contributor

Choose a reason for hiding this comment

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

After thinking about it a bit more, I think having the multiple clauses is the more idiomatic way of dealing with this. We can instead, save the message and error objects in variables in each of the except clauses and introduce a finally clause that checks if we recorded any errors, and if so, then log + send to error handler. WDYT? @aliabbasrizvi

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @mikeng13 ... yes that is more idiomatic and I believe we should adopt that.

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

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

LGTM

@mikeproeng37 mikeproeng37 merged commit c2ea908 into master Sep 11, 2018
@aliabbasrizvi aliabbasrizvi deleted the oakbani/prevent-newer-datafile branch September 28, 2018 18: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.

5 participants