Convert pulp.server.db.connection to manage the database connection with an object
This Task is designed to solve two problems. (1) To remove the use of globals and replace it with a class based design and (2) to consolidate the database getter methods onto the class managing the database singleton.
I generally avoid the use of globals because they casually share state and promote a non object oriented paradigm. Using a class to store any globals requires developers to be more explicit, and access functions can be getter methods instead of module level functions.
1) Introduce a new class in pulp.server.db.connection and move the initialize method into it as a @classmethod. Refactor all calls to the old pulp.server.db.connection.initialize method to use the new class method. The @classmethod initialize should store the _CONNECTION and _DATABASE objects as class attributes.
2) Move the get_collection(), get_database(), and get_connection() methods to be @classmethods on the new class introduced in (1). Refactor the usages of these 3 functions to use them as classmethods.
3) Ensure that get_collection(), get_database(), and get_connection() raise a consistent Exception if initialize() has not already been called.
4) Update the associated tests
#9 Updated by bmbouter over 1 year ago
Pulp 2 is approaching maintenance mode, and this Pulp 2 ticket is not being actively worked on. As such, it is being closed as WONTFIX. Pulp 2 is still accepting contributions though, so if you want to contribute a fix for this ticket, please reopen or comment on it. If you don't have permissions to reopen this ticket, or you want to discuss an issue, please reach out via the developer mailing list.
Please register to edit this issue