Skip to content

Latest commit

 

History

History
47 lines (29 loc) · 2.09 KB

8-08-quality.md

File metadata and controls

47 lines (29 loc) · 2.09 KB

8. Code quality

Code quality was covered in week 4.

This activity is a prompt to remind you.

Docstrings and exception handling have been omitted from the activities this week to keep focus on the queries but should be considered when you write your coursework code.

Some SQLModel specific considerations:

  1. Structure - refer to SQLModel specific guidance

  2. Docstrings for classes - refer to the guidance for the style you are using e.g. Google style

  3. Linting

    When you create the database you import models, yet the import is not explicitly used in the Python code. The linter will warn about this. It is an example of a situation you can ignore.

    Try flake8 --max-line-length=100 src/activities/starter/db_wk8/database.py in the terminal pane.

  4. Exception handling in SQLModel

    SQLModel extends pydantic and SQLAlchemy so you would be handling Exceptions from these packages. Some of the common ones you might experience:

    • pydantic: ValidationError
    • sqlalchemy: IntegrityError, SQLAlchemyError (base class for sqlalchemy errors), OperationalError, see documentation

    Have a look at the following tutorials on Exception handling for these:

Activity: Add exception handling

There are no tutor solutions to this activity.

Uncomment and run each of the functions in main in error_code.py.

Identify the exceptions raised then try to handle them.

Logging errors

A complementary technique to exception handling is to log errors as well to help with debugging. This is not taught until COMP0034 though you may want to investigate if you have time.