mathesar icon indicating copy to clipboard operation
mathesar copied to clipboard

Reduce db functions to one SQLAlchemy operation per function

Open silentninja opened this issue 2 years ago • 10 comments

Problem

We have decided to use attnums when passing a column reference as arguments but most of the SQLAlchemy operations use column name, so we need to fetch the column name before an SQLAlchemy operation, this can lead to referencing a wrong column in case there are multiple SQLAlchemny operations within a single function and one of those happens to change a column name.

Proposed solution

Each function should use only one SQLAlchemy operation so a column name altering operation won't have any effect on other operations.

silentninja avatar Feb 24 '22 00:02 silentninja

@silentninja I would like to work on this issue. Can you please elaborate on this issue and how to get started?

vrutik2809 avatar Mar 13 '22 17:03 vrutik2809

@vrutik2809 I've assigned this issue to you. @silentninja will get back to you when he's back online. In the meanwhile, please feel free to ask your questions directly on our matrix channels.

pavish avatar Mar 14 '22 05:03 pavish

Thank you

vrutik2809 avatar Mar 14 '22 08:03 vrutik2809

@vrutik2809 I think this issue needs some in-depth knowledge about the codebase, I was wrong about tagging this as a good first issue. I have unassigned you, Please feel free to work on some other issue. Really sorry for the inconvenience

silentninja avatar Mar 14 '22 09:03 silentninja

No problem. I will look for another issue

Thanks

vrutik2809 avatar Mar 14 '22 10:03 vrutik2809

@silentninja In the function alter_column inside db/columns/operations/alter.py each method are given column_attnum and those methods get the name of the column using attnum how can this lead to referencing a wrong column?

Anish9901 avatar Mar 28 '22 19:03 Anish9901

Quoted from the proposed solution

Each function should use only one SQLAlchemy operation

@Anish9901 Function alter_column does not call any SQLALchemy operations, it composes of multiple functions which take attnum as parameters and does a single SQL operation, essentially acting as a attnum wrapper for a SQL operation, such functions don't have to be changed.

This issue is about splitting the function that uses multiple SQL operations(using SQL alchemy). For example, db.columns.operations.alter._batch_alter_table_columns calls multiple SQLAlchemy operation within it, https://github.com/centerofci/mathesar/blob/e2ab941c4ade4737f4e14ed72b8cb3ee67f341ac/db/columns/operations/alter.py#L213 https://github.com/centerofci/mathesar/blob/e2ab941c4ade4737f4e14ed72b8cb3ee67f341ac/db/columns/operations/alter.py#L218

silentninja avatar Mar 30 '22 16:03 silentninja

@silentninja I have understood the issue, I would like to work on fixing it, can you please assign me?

Anish9901 avatar Mar 30 '22 17:03 Anish9901

Thanks @Anish9901 I've assigned this to you.

seancolsen avatar Mar 30 '22 18:03 seancolsen

@silentninja I have made a PR #1266 regarding this issue please take a look.

Anish9901 avatar Apr 05 '22 17:04 Anish9901

@Anish9901 are you still working on this?

kgodey avatar Sep 07 '22 22:09 kgodey

Yes, @kgodey the only thing left to add are test cases, as @mathemancer said it could be fairly technical to write them, I'll work on it ASAP.

Anish9901 avatar Sep 08 '22 05:09 Anish9901

Given that we're planning to go a different direction which will change how we use SQLAlchemy, I think we can consider this issue resolved by @Anish9901 's PR #1266 for now.

mathemancer avatar Sep 08 '22 13:09 mathemancer