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 records.list rpc function #3691

Merged
merged 28 commits into from
Jul 19, 2024
Merged

Add records.list rpc function #3691

merged 28 commits into from
Jul 19, 2024

Conversation

mathemancer
Copy link
Contributor

@mathemancer mathemancer commented Jul 15, 2024

Related to #3690

Adds an initial records.list RPC function.

Technical details

The filter, group, and search kwargs aren't wired up yet, but can be submitted.

As usual, the included documentation should be sufficient to describe the functions for review.

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 changed the title Records list rpc Add records.list rpc function Jul 16, 2024
@mathemancer mathemancer added this to the Beta milestone Jul 16, 2024
@mathemancer mathemancer added the pr-status: review A PR awaiting review label Jul 16, 2024
@mathemancer mathemancer marked this pull request as ready for review July 16, 2024 06:52
Copy link
Contributor

@seancolsen seancolsen left a comment

Choose a reason for hiding this comment

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

Looks good!

  • I skimmed the code. No red flags stuck out to me. Though I imagine Anish will go over in it more detail.

  • I ran it and verified that it works.

  • I stress-tested the limit, offset, and order parameters a bit and couldn't find anything amiss.

  • The general structure of the output looks good.

The only (slight) concern I have is this...

The cell values for some types are not formatted the same way as in the REST API. For example:

REST RPC
1960-07-24 AD 1960-07-24
2014-04-21T17:30:44.0 AD 2014-04-21T17:30:44
P0Y0M0DT777H55M39S 777:55:39

It's hard for me to quickly identify whether the change in formatting will be problematic or not. We would certainly notice this later down the road during QA though, so I'm okay kicking this can down the road and seeing what problems pop up. They'll be easier to address when we have this new RPC API better integrated into the front end, because at that point we'll be able to make a more informed decision about the quickest path to fixing any issues (i.e. front end or back end).

@seancolsen seancolsen removed their assignment Jul 16, 2024
@mathemancer
Copy link
Contributor Author

Looks good!

  • I skimmed the code. No red flags stuck out to me. Though I imagine Anish will go over in it more detail.
  • I ran it and verified that it works.
  • I stress-tested the limit, offset, and order parameters a bit and couldn't find anything amiss.
  • The general structure of the output looks good.

The only (slight) concern I have is this...

The cell values for some types are not formatted the same way as in the REST API. For example:

REST RPC
1960-07-24 AD 1960-07-24
2014-04-21T17:30:44.0 AD 2014-04-21T17:30:44
P0Y0M0DT777H55M39S 777:55:39
It's hard for me to quickly identify whether the change in formatting will be problematic or not. We would certainly notice this later down the road during QA though, so I'm okay kicking this can down the road and seeing what problems pop up. They'll be easier to address when we have this new RPC API better integrated into the front end, because at that point we'll be able to make a more informed decision about the quickest path to fixing any issues (i.e. front end or back end).

I'll look into the formatting. Great catch, thank you!

@mathemancer
Copy link
Contributor Author

mathemancer commented Jul 18, 2024

@Anish9901 When you review: I just ended up emulating the current REST endpoint responses w.r.t. the formatting. I validated this by adding tests adapted directly from the python tests for type formatting. However, there were some preexisting problems that remain as of this PR:

  • No formatting of types within arrays, and
  • The interval type formatting doesn't really work in the front end (same as before).

I think we can address these issues as feature requests in a future PR.

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.

The PR looks great overall @mathemancer, and I find the idea of using the attnums as column identifiers instead of referring to them by their names brilliant! However, I think I have found a pretty significant bug here which is worth fixing.

mathesar/rpc/records.py Outdated Show resolved Hide resolved
Comment on lines 3393 to 3396
SELECT string_agg(format('msar.format_data(%I) AS %I', attname, attnum), ', ')
FROM pg_catalog.pg_attribute
WHERE
attrelid = tab_id AND attnum > 0 AND has_column_privilege(attrelid, attnum, 'SELECT');
Copy link
Member

Choose a reason for hiding this comment

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

This breaks for a table from which previously existing column(s) have been dropped.
Here is the specific error:

mathesar=# select msar.list_records_from_table('"Library Management"."Items"'::regclass::oid, NULL, NULL, NULL, NULL, NULL, NULL);
ERROR:  column "........pg.dropped.4........" does not exist
LINE 5: ...data("Acquisition Date") AS "3", msar.format_data("........p...
                                                             ^
QUERY:  
    WITH count_cte AS (
      SELECT count(1) AS count FROM "Library Management"."Items"
    ), results_cte AS (
      SELECT msar.format_data(id) AS "1", msar.format_data("Barcode") AS "2", msar.format_data("Acquisition Date") AS "3", msar.format_data("........pg.dropped.4........") AS "4", msar.format_data("Book") AS "5" FROM "Library Management"."Items" ORDER BY "1" ASC LIMIT NULL OFFSET NULL
    )
    SELECT jsonb_build_object(
      'results', jsonb_agg(row_to_json(results_cte.*)),
      'count', max(count_cte.count)
    )
    FROM results_cte, count_cte
    
CONTEXT:  PL/pgSQL function msar.list_records_from_table(oid,integer,integer,jsonb,jsonb,jsonb,jsonb) line 19 at EXECUTE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! I've pushed a fix and a test. Should be fine now.

@mathemancer mathemancer requested a review from Anish9901 July 19, 2024 10:30
@Anish9901 Anish9901 enabled auto-merge July 19, 2024 10:40
@Anish9901 Anish9901 added this pull request to the merge queue Jul 19, 2024
Merged via the queue into develop with commit 2f698bf Jul 19, 2024
37 checks passed
@Anish9901 Anish9901 deleted the records_list_rpc branch July 19, 2024 11:06
@kgodey kgodey modified the milestones: Beta, Pre-beta test build #1 Sep 18, 2024
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.

4 participants