Build-time dependency checking #188
Replies: 2 comments
-
It's a good idea. I had a similar thought recently - would it be possible to build a Piccolo linter? Something like flake8 will catch some errors, for example: class MyTable(Table):
title = Varchar()
# Error - MyTable.name doesn't exist
await MyTable.select(MyTable.name).run() There are more advanced use cases though which it might not catch. class Owner(Table):
name = Varchar()
class MyTable(Table):
title = Varchar()
owner = ForeignKey(Owner)
# It might not catch this, as there's some Python magic going on to make this possible:
await MyTable.select(MyTable.owner.name).run() Piccolo has the ability to create Pydantic models from Piccolo tables: https://piccolo-api.readthedocs.io/en/latest/crud/serializers.html But there's no direct reference between the Pydantic model and the table used to create it at the moment. For example: >>> MyPydanticModel.table
MyTable
>>> MyPydanticModel.name.column
Varchar Which might make it harder to create a linter which analyses the entire stack (FastAPI, Pydantic, and Piccolo). It should be possible to modify Anyway ... just my thoughts. |
Beta Was this translation helpful? Give feedback.
-
I guess the alternative is to ensure 100% front-to-back test coverage -- which is a sensible aspiration in its own right anyway. |
Beta Was this translation helpful? Give feedback.
-
Just thinking out loud here -- may not directly be a Piccolo question. One of the things I'd love to achieve is build-time change impact analysis, by which I mean traceability of changes from database all the way through to user interface. I've done this before in a large codebase (> 2 million lines) but it was in Java, with a data layer generated from a model, and user interfaces constructed using a DSL that turned into JSPs. Problematic changes that weren't mapped through all the layers were caught, by and large, at build/compile time.
I'm thinking that such a thing isn't really achievable in Python. One of the good things about Piccolo is that field references can be checked by a Linter. Similarly for fastapi interfaces with Pydantic models. But what about mapping between the two, and/or mappings in Jinja2 templates. Maybe I could write a Linter for the latter. Still don't think I could fully achieve what I want in a dynamically typed language, even with type hints. Just throwing it out there as a thought.
Beta Was this translation helpful? Give feedback.
All reactions