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

Add columns.list function #3556

Merged
merged 29 commits into from May 9, 2024
Merged

Conversation

mathemancer
Copy link
Contributor

@mathemancer mathemancer commented Apr 26, 2024

Fixes #3549
Fixes #3571

This adds an RPC function called columns.list that takes a database_id and table_oid as input, and returns information about the columns of the identified table.

Technical details

  • The function is documented in the new documentation added in this PR, and those docs should be sufficient to explain its usage, and the return format. If not, request a change to those docs.
  • The SQL test suite was modified to avoid using the pgTAP setup function feature, since that bogs the tests down too much.
  • This PR also provides an example of how and where I think we should organize the code for the RPC functions. Of note:
    • mathesar.rpc.columns.list_ is kept pretty simple. It's responsible for getting a connection using the provided utility function, and then calls other functions to actually gather data.
    • mathesar.rpc.columns.list_ doesn't directly use the connection to access the database, but it does call the db access function within a managed context.
    • mathesar.utils.columns.get_raw_display_options is a bit of scaffolding for now, since the new model hasn't been made yet.
    • However, its signature shouldn't change. In particular, it's supposed to manage access using the passed database_id and user
    • The mathesar.rpc.utils.connect function is also a stub for now, but its signature should also stay the same.
    • The tests are supposed to serve as an example of how I think we should proceed on testing the backend, at least until beta.
    • No actual calls to the database for unit testing.
    • More mocking to isolate functionality of piece being tested.
    • mathesar.tests.rpc.test_endpoints tests that the expected functions are shown, at that each is defined with the expected decorators are applied. Nothing more.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@mathemancer mathemancer linked an issue Apr 26, 2024 that may be closed by this pull request
@mathemancer mathemancer requested a review from Anish9901 May 7, 2024 08:06
@mathemancer mathemancer assigned Anish9901 and unassigned mathemancer May 7, 2024
@mathemancer mathemancer changed the base branch from develop to architectural_overhaul May 7, 2024 08:30
@mathemancer mathemancer added the pr-status: review A PR awaiting review label May 7, 2024
@mathemancer mathemancer added this to the Beta milestone May 7, 2024
@mathemancer mathemancer marked this pull request as ready for review May 7, 2024 08:33
@mathemancer mathemancer changed the title Permissions stub Add columns.list function May 7, 2024
Copy link
Member

@Anish9901 Anish9901 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, I've requested some minor changes.

from mathesar.utils.columns import get_raw_display_options


class TypeOptions(TypedDict, total=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the total flag for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, setting it to False is an explicit flag to let the reader know that not all fields of the dictionary are required. It's not enforced in any way (except by linters).

Args:
db_id: The Django id corresponding to the Database.
"""
print("User is: ", user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed a print statement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually left that on purpose for the moment. My thinking is that this function body is going to be replaced once we have the permissions stuff worked out. For now, I'd like to leave that as a placeholder for logic that will use the user to get a connection credential.

Comment on lines +24 to +37
def get_psycopg_connection(db_model):
"""
Get a psycopg connection, given a Database model.

Args:
db_model: The Django model corresponding to the Database.
"""
return psycopg.connect(
host=db_model.host,
port=db_model.port,
dbname=db_model.db_name,
user=db_model.username,
password=db_model.password,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have this in connect() itself? I thought we discussed that we'd always need to call connect with appropriate arguments and won't be opening random connections elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For any user request, this is true. However, we have a few things (installation, upgrade) that won't have a user associated with them. I wanted to leave this function available for those use cases.

Comment on lines +500 to +512
WHEN 1 << 2 THEN 'year'
WHEN 1 << 1 THEN 'month'
WHEN 1 << 3 THEN 'day'
WHEN 1 << 10 THEN 'hour'
WHEN 1 << 11 THEN 'minute'
WHEN 1 << 12 THEN 'second'
WHEN (1 << 2) | (1 << 1) THEN 'year to month'
WHEN (1 << 3) | (1 << 10) THEN 'day to hour'
WHEN (1 << 3) | (1 << 10) | (1 << 11) THEN 'day to minute'
WHEN (1 << 3) | (1 << 10) | (1 << 11) | (1 << 12) THEN 'day to second'
WHEN (1 << 10) | (1 << 11) THEN 'hour to minute'
WHEN (1 << 10) | (1 << 11) | (1 << 12) THEN 'hour to second'
WHEN (1 << 11) | (1 << 12) THEN 'minute to second'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing!!!

from mathesar.models.users import User


def test_columns_list(rf, monkeypatch):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a docstring for the fixtures used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'll add a docstring at the top of the file. I think that's going to be better in general, since fixtures are defined in such a way that they're file-wide and not restricted to any given test function.

@mathemancer mathemancer requested a review from Anish9901 May 9, 2024 06:29
@mathemancer
Copy link
Contributor Author

Okay, I think I've addressed everything, @Anish9901 .

Copy link
Member

@Anish9901 Anish9901 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@Anish9901 Anish9901 merged commit ddab8b9 into architectural_overhaul May 9, 2024
34 checks passed
@Anish9901 Anish9901 deleted the permissions_stub branch May 9, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement columns.list RPC method Implement stub function to get DB connection during development
2 participants