Skip to content

Refactor build_where_text to use psycopg2.sql #283

@hollowtree11

Description

@hollowtree11

The current implementation of build_where_text in PostgresConnector relies on manual string concatenation and f-strings to build SQL queries. Manual SQL building is prone to security vulnerabilities and is often where third-party library updates break code. We should refactor this method to use the psycopg2.sql module. This allows us to build queries using SQL, Identifier, and Placeholder objects, ensuring that table names, column names, and values are handled safely by the driver.

TASKS : This seems like a valid use for this library, specifically because we need SOME adapter to interface with our database anyway.

  1. use Psyco in the build_where_text as described.
  2. Refactor with build_family_where_text in mind. Existing code should minimize redundency, and this may mean taking parts out of build_where_text into their own functions (designers choice), as long as it works it will be fine, but getting both of these functions into a more maintainable state is idea, to include a more obvious way for future devs to extend/build upon these methods. This could mean that this method turns into a monolith or gets split into many different methods.
  3. (separate task is also being opened) replace psychopg2.extras DictCursor with custom code.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions