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

Type logic refactor #1222

Merged
merged 84 commits into from
May 24, 2022
Merged

Type logic refactor #1222

merged 84 commits into from
May 24, 2022

Conversation

dmos62
Copy link
Contributor

@dmos62 dmos62 commented Mar 23, 2022

The initial goal of refactor was to centralize and improve our db/ui type logic, of which there is a lot. That dominoed into a lot of secondary refactors, because I often couldn't make the changes I needed outright.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master 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.

@dmos62 dmos62 added affects: technical debt Improves the state of the codebase work: backend Related to Python, Django, and simple SQL status: draft labels Mar 23, 2022
@dmos62 dmos62 added this to the [07] Initial Data Types milestone Mar 23, 2022
@dmos62 dmos62 self-assigned this Mar 23, 2022
Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

Overall, I think this is going to be a massive improvement. We'll need to go through the code base and make sure no function deals with bare SA type classes, ever, except to convert them to the appropriate Enum member, or at the last point when creating a column. I'm not sure how to guarantee that long-term. Maybe a ban on imports of SA type classes outside the types.base module?

db/types/base.py Show resolved Hide resolved

def get_sa_class(self, engine):
"""
Returns the SA class corresponding to this type or None if this type is not supported by
Copy link
Contributor

Choose a reason for hiding this comment

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

This will more precisely return a SA class corresponding to this type. In particular, we will return the SQL Standard or Vendor-Specific SA class for the type, with the exceptions of name and "char", which will return (for now) the String generic SA class.

See https://docs.sqlalchemy.org/en/14/core/type_basics.html#sql-standard-and-multiple-vendor-types

@dmos62 dmos62 requested a review from seancolsen May 23, 2022 15:47
@dmos62
Copy link
Contributor Author

dmos62 commented May 23, 2022

Latest revision adds pytest-xdist support. To use it:

  • install pytest-xdist on your development docker instance, or rebuild it;
  • add -n [number of CPUs (or cores?) you have] to your pytest call: something like pytest -vv --ignore=mathesar/tests/integration/ -n 4;
    • -n auto should also work, but it's failed on me at times.

@dmos62
Copy link
Contributor Author

dmos62 commented May 23, 2022

Note, I added -n auto to setup.cfg, so that tests run in parallel automatically. Fall back to using -n [specific number of parallel threads] if that doesn't work for some reason. -n 0 disables parallelization.

@dmos62
Copy link
Contributor Author

dmos62 commented May 24, 2022

I see that some e2e tests have failed in the Github runner, while they pass fine on my machine. I'm not sure if this is a fluke or if there's an actual problem. Rerunning the test suite.

@dmos62 dmos62 requested a review from mathemancer May 24, 2022 05:39
@dmos62
Copy link
Contributor Author

dmos62 commented May 24, 2022

I see that some e2e tests have failed in the Github runner, while they pass fine on my machine. I'm not sure if this is a fluke or if there's an actual problem. Rerunning the test suite.

I'm guessing that the problem is that e2e test runner is choking, because I've enabled test parallelization (this runner is using 2 parallel threads). I'll disable automatic parallelization for e2e tests, when I get online.

@dmos62
Copy link
Contributor Author

dmos62 commented May 24, 2022

I disabled test parallelization on GitHub's e2e test workflow and now it seems to be passing. I presume the problem was that parallelization slowed down the test runner too much. That's not a concern in a regular development environment, as far as I can tell.

I also removed TIME and TIMESTAMP types from the codebase, since as @mathemancer pointed out, we'll never reflect them (we'll reflect types like TIME_WITH_TIME_ZONE instead).

@dmos62 dmos62 dismissed mathemancer’s stale review May 24, 2022 12:30

Many changes made, including the requested changes.

Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

Overall, a massive improvement, good work.

I have some qualms with approving, since I admittedly wasn't able to completely verify everything, but:

  • I looked through tests to asses whether they're still valid; I think they are.
  • I looked through code to see if I noticed any obvious bugs or problems; none found.
  • I ran the service and fiddled around with the API to see if I noticed any obvious regressions; none found.

I think we should get this merged ASAP. @dmos62 is it ready to go?

db/types/categories.py Outdated Show resolved Hide resolved
db/types/categories.py Outdated Show resolved Hide resolved
Comment on lines +14 to +16
id: str # noqa: NT001
display_name: str # noqa: NT001
db_types: Collection[DatabaseType] # noqa: NT001
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these needed?

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 clarity. These mixins only support objects that have these attributes. I didn't see another way to state that concisely and clearly. Also, this being actual type annotations, instead of a comment, helps with IDE complaining that referencing these attributes in this class is a mistake.

I'm open to getting rid of it, but I think this is a useful exception to the no-type-hints rule.

@mathemancer mathemancer enabled auto-merge May 24, 2022 13:10
@mathemancer mathemancer disabled auto-merge May 24, 2022 13:17
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.

@dmos62 You've clearly been busy with this PR 😲

I'm not reviewing the back-end code, but I looked over the front end changes and E2E changes. I added a couple small commits. Looks good!

@@ -15,8 +15,7 @@ services:
service:
build:
context: .
# Change this to Dockerfile.integ-tests to be able to run e2e integ tests
dockerfile: Dockerfile
dockerfile: ${DOCKERFILE}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great idea, moving this config to .env. I added 7cdfa7c to update the documentation to reflect this change. If I'm understanding this change correctly, then all existing devs will need to add DOCKERFILE=Dockerfile or DOCKERFILE=Dockerfile.integ-tests to their .env before they can re-build the container. Yes? If so, we should give everyone a heads up after merging this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! I had forgotten about this! Thanks!

Specifically, my suggestion would have been to do cp .env.example .env.

@@ -22,6 +23,7 @@ def test_convert_text_column_to_number(page, go_to_patents_data_table):
expect(page.locator(toast_box)).to_be_visible()


@pytest.mark.skip(reason="unclear why test is failing: deferring for later")
Copy link
Contributor

Choose a reason for hiding this comment

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

@dmos62 was this failing for you locally? Or just in CI? I just ran it locally and it passed for me. Maybe we don't need to skip it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was failing for me locally. Could we try and resolve this outside this PR? I'd love to get this merged soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. Sounds good.

@dmos62 dmos62 enabled auto-merge May 24, 2022 18:18
@dmos62
Copy link
Contributor Author

dmos62 commented May 24, 2022

I've enabled auto-merge. Thanks for the reviews @mathemancer and @seancolsen!

I also disabled test parallelization by default, because @mathemancer discovered a bug, where we can't have more than 7 threads, due to the testing suite not cleaning up unused database connections (i think that's the reason).

@dmos62 dmos62 merged commit 66f34de into master May 24, 2022
@dmos62 dmos62 deleted the some-type-logic-refactor branch May 24, 2022 18:39
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 work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

4 participants