From 97f68d8323fdb756cf32795f2cdd1993bfe4ad35 Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:59:49 +0100 Subject: [PATCH 1/2] fix: falsey tests for var which can be None * Tests for falsity of file_schema_valid was changed in response to flake8 warnings about use of '==' , but recommended action was not semantically equivalent--this commit restores original behaviour and passes flake8 checks. --- src/library/validate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/library/validate.py b/src/library/validate.py index cca0f28..f8b0be8 100644 --- a/src/library/validate.py +++ b/src/library/validate.py @@ -33,7 +33,7 @@ def process_hash_list(document_datasets): file_schema_valid = file_data[6] publisher_black_flag = file_data[7] is not None - if not file_schema_valid and downloaded > ( + if file_schema_valid is False and downloaded > ( now - timedelta(hours=config["VALIDATION"]["SAFETY_CHECK_PERIOD"]) ): logger.info( @@ -43,7 +43,7 @@ def process_hash_list(document_datasets): ) continue - if not file_schema_valid and publisher_black_flag: + if file_schema_valid is False and publisher_black_flag: logger.info( "Skipping Schema Invalid file for Full Validation since publisher: " f"{publisher} is black flagged for hash: {file_hash} and id: {file_id}" @@ -115,7 +115,7 @@ def process_hash_list(document_datasets): ) continue - if not file_schema_valid and downloaded > ( + if file_schema_valid is False and downloaded > ( now - timedelta(hours=config["VALIDATION"]["SAFETY_CHECK_PERIOD"]) ): logger.info( @@ -125,7 +125,7 @@ def process_hash_list(document_datasets): ) continue - if not file_schema_valid and publisher_black_flag: + if file_schema_valid is False and publisher_black_flag: logger.info( f"Skipping Schema Invalid file for Full Validation since publisher: {publisher} " f"is flagged for hash: {file_hash} and id: {file_id}" From c05999a090b65e8cdaa6674ecebda0bed45f6ef9 Mon Sep 17 00:00:00 2001 From: Simon K <6615834+simon-20@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:37:23 +0100 Subject: [PATCH 2/2] fix: change tests to check explicitly for True, False * These tests were changed to use 'variable' and 'not variable' in response to flake8 warnings, but should have used 'is True', 'is False', because the variable can be None --- src/library/validate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/library/validate.py b/src/library/validate.py index f8b0be8..71f046d 100644 --- a/src/library/validate.py +++ b/src/library/validate.py @@ -43,7 +43,7 @@ def process_hash_list(document_datasets): ) continue - if file_schema_valid is False and publisher_black_flag: + if file_schema_valid is False and publisher_black_flag is True: logger.info( "Skipping Schema Invalid file for Full Validation since publisher: " f"{publisher} is black flagged for hash: {file_hash} and id: {file_id}" @@ -104,7 +104,7 @@ def process_hash_list(document_datasets): ) try: body = schema_response.json() - if body["valid"] or not body["valid"]: + if body["valid"] is True or body["valid"] is False: db.updateDocumentSchemaValidationStatus(conn, file_id, body["valid"]) file_schema_valid = body["valid"] else: @@ -125,7 +125,7 @@ def process_hash_list(document_datasets): ) continue - if file_schema_valid is False and publisher_black_flag: + if file_schema_valid is False and publisher_black_flag is True: logger.info( f"Skipping Schema Invalid file for Full Validation since publisher: {publisher} " f"is flagged for hash: {file_hash} and id: {file_id}" @@ -141,7 +141,7 @@ def process_hash_list(document_datasets): full_url = config["VALIDATION"]["FULL_VALIDATION_URL"] # only need meta=true for invalid files to "clean" them later - if not file_schema_valid: + if file_schema_valid is False: full_url += "?meta=true" full_response = requests.post( full_url,