Skip to content

Commit

Permalink
[web] Timestamp annotation is not checked anymore
Browse files Browse the repository at this point in the history
Earlier it was checked whether "timestamp" annotation had a proper
"timedate" format. It turns out that sometimes it's more convenient to
order reports based on a different time measure. For this reason we
allow any string as "timestamp" annotation.
  • Loading branch information
bruntib committed Jan 28, 2025
1 parent 1d81ff6 commit 6ca79d7
Showing 1 changed file with 3 additions and 48 deletions.
51 changes: 3 additions & 48 deletions web/server/codechecker_server/api/mass_store_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,9 @@ def __add_report_context(self, session, file_path_to_id):
db_report.id, data_type))

if report.annotations:
self.__validate_and_add_report_annotations(
session, db_report.id, report.annotations)
for key, value in report.annotations.items():
session.add(
ReportAnnotations(db_report.id, key, value))

session.flush()

Expand Down Expand Up @@ -1148,52 +1149,6 @@ def get_missing_file_ids(report: Report) -> List[str]:

return True

def __validate_and_add_report_annotations(
self,
session: DBSession,
report_id: int,
report_annotation: Dict
):
"""
This function checks the format of the annotations. For example a
"timestamp" annotation must be in datetime format. If the format
doesn't match then an exception is thrown. In case of proper format the
annotation is added to the database.
"""
allowed_types = {
"datetime": {
"func": datetime.fromisoformat,
"display": "date-time in ISO format"
},
"string": {
"func": str,
"display": "string"
}
}

allowed_annotations = {
"timestamp": allowed_types["datetime"],
"testsuite": allowed_types["string"],
"testcase": allowed_types["string"]
}

for key, value in report_annotation.items():
try:
allowed_annotations[key]["func"](value)
session.add(ReportAnnotations(report_id, key, value))
except KeyError:
# pylint: disable=raise-missing-from
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.REPORT_FORMAT,
f"'{key}' is not an allowed report annotation.",
allowed_annotations.keys())
except ValueError:
# pylint: disable=raise-missing-from
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.REPORT_FORMAT,
f"'{value}' has wrong format. '{key}' annotations must be "
f"'{allowed_annotations[key]['display']}'.")

def __get_report_limit_for_product(self):
with DBSession(self.__config_database) as session:
product = session.query(Product).get(self.__product.id)
Expand Down

0 comments on commit 6ca79d7

Please sign in to comment.