Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checks for whether a database type is installed #1050

Closed
dmos62 opened this issue Feb 7, 2022 · 2 comments
Closed

Fix checks for whether a database type is installed #1050

dmos62 opened this issue Feb 7, 2022 · 2 comments
Labels
affects: technical debt Improves the state of the codebase type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@dmos62
Copy link
Contributor

dmos62 commented Feb 7, 2022

Problem description

While reviewing #1022, @mathemancer noticed that some of our methods used to determine whether or not a database type is installed on the database are problematic. The following comment by @mathemancer gives hints:

I noticed a problem with the function that checks whether a type is installed. To be honest, that logic is a bit all over the place both in the db/types/base.py file as well as the db/types/operations/cast.py file, and should probably be tidied up.

Mentioned code areas:

  • db/types/base.py::get_available_types;
  • db/types/operations/cast.py.

Expected outcome

Refactor relevant files and methods to have an accurate picture of which types are installed (on a given database) and which are not.

@dmos62 dmos62 added type: bug Something isn't working affects: technical debt Improves the state of the codebase work: backend Related to Python, Django, and simple SQL status: draft labels Feb 7, 2022
@dmos62 dmos62 added this to the [07.2] 2022-02 improvements milestone Feb 7, 2022
@dmos62 dmos62 mentioned this issue Feb 7, 2022
7 tasks
@dmos62
Copy link
Contributor Author

dmos62 commented Feb 7, 2022

@mathemancer To be clear, is the problem that we're using engine.dialect.ischema_names to check whether a type is on the database? Since the "engine mapping", as you've called it, is not proxy for what is installed on the database?

Is this get_available_types method then the root of the problem?

def get_available_types(engine):
    """
    Returns a dict where the keys are database type names defined on the database associated with
    provided Engine, and the values are their SQLAlchemy classes.
    """
    return engine.dialect.ischema_names

Below is what I did to get the installed functions.

def _get_functions_defined_on_database(engine):
    metadata = MetaData()
    pg_proc = Table('pg_proc', metadata, autoload_with=engine, schema='pg_catalog')
    select_statement = select(pg_proc.c.proname)
    return tuple(
        function_name
        for function_name, in engine.connect().execute(select_statement)
    )

Is the solution to do the same for types?

@kgodey kgodey modified the milestones: [06.2] 2022-04 improvements, [08.1] 2022-05 improvements May 2, 2022
@kgodey kgodey modified the milestones: [08.1] 2022-05 improvements, High Priority Jun 1, 2022
@github-actions
Copy link

This issue has not been updated in 90 days and is being marked as stale.

@github-actions github-actions bot added the stale label Mar 27, 2023
@rajatvijay rajatvijay removed the stale label Mar 29, 2023
@Anish9901 Anish9901 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: technical debt Improves the state of the codebase type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

No branches or pull requests

5 participants