CodeSOD: The Base Model

Penny uses a Python ORM. Like most ORMs, it involves a lot of "inherit from a BaseModel class, and get all your database access stuff for "free". Or at least, it used to. They've released an update.

def __init__(self, *args, **kwargs): if hasattr(self, "ACCESS_POLICY_VIEWSET_NAME"): deprecation_logger.warn( f"The model {self.__class__} defines the 'ACCESS_POLICY_VIEWSET_NAME' class " f"attribute which is no longer required and is discouraged to be set." ) return super().__init__(*args, **kwargs)

Now, this is an interesting class of breaking change. Everyone like Penny has been class MyEntity(BaseModel) for the entire time they've been using the framework. Whether or not that's a good way to do ORMs, it's going to disrupt a lot of people's code.

In Penny's case, their application uses the ORM for syncing data between large databases, and they're large and complicated- thousands of entities have to get synced, and each entity inherits from that BaseModel class. This means that not only does nearly every entity need to be changed, but also that every time they run their code, they generate many many thousands of lines of logged warnings.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.