-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#4898) Initially, when the column `repository_metadata` was added to the `DbNode` table, it was set to be nullable since a significant number of nodes will not actually have any files and therefore this value would be empty. However, to prevent clients having to deal with a null-value, the front-end ORM `Node.repository_metadata` property would return an empty dictionary in this case, such that the return type is always a dictionary. The main argument was that this would prevent unnecessary bytes from being stored in the database. However, a bug surfaced where some code expected a dictionary for the `repository_metadata` but got `None`. This particular instance was in the import code, which circumvents the ORM and went straight to the database. This is of course undesirable, but it also happens through the `QueryBuilder` that doesn't transform the returned attributes of entities through the ORM interface. Given that there are a number of layers from the ORM to the database, making sure that the typing across all layers is consistent would be tricky and prone to more bugs. The most secure solution is to simply set an empty dict as the default on the database level. The added cost to the database size should still be minimal and so is an acceptable downside to the increased stability of the code. Note that the column in the model is declared both with a server default as well as a default on the ORM level. The reason is that the server default is required for the migration. If the column were to be added without the default, existing rows would violate the non-nullable clause. For consistency, the server default is also added to the table column declaration. The ORM default is necessary to guarantee that an empty dictionary is set on a new `DbNode` instance when it is created. SqlAlchemy cannot execute the server default and so would leave it as `None`, but we require that even for unstored instances, the value defaults to an empty dictionary.
- Loading branch information
Showing
10 changed files
with
20 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters