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: unit test failing if not local db #3307

Merged
merged 6 commits into from
Jul 3, 2023

Conversation

gabrielmbmb
Copy link
Member

Description

The API startup event was using the argilla.server.database.get_async_db function to get a DB session to check if the default argilla user exists. We were overriding the get_async_db dependency for the API endpoints, but we were not mocking the function when being used from the API startup, and therefore the function was returning a session to the local sqlite DB ($HOME/.argilla/argilla.db). If the sqlite local db file didn't exist and the migrations hadn't been applied, then a sqlalchemy.errors. OperationalError was being raised as the User table didn't exist.

Type of change

(Please delete options that are not relevant. Remember to title the PR according to the type of change)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (change restructuring the codebase without changing functionality)
  • Improvement (change adding some improvement to an existing functionality)
  • Documentation update

How Has This Been Tested

Running the tests without the $HOME/.argilla/argilla.db file doesn't raise an exception anymore.

Checklist

  • I added relevant documentation
  • follows the style guidelines of this project
  • I did a self-review of my code
  • I made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I filled out the contributor form (see text above)
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

@gabrielmbmb gabrielmbmb added the type: bug Indicates an unexpected problem or unintended behavior label Jul 3, 2023
@gabrielmbmb gabrielmbmb added this to the v1.13 milestone Jul 3, 2023
@gabrielmbmb gabrielmbmb changed the title Fix/unit test failing if not local db fix: unit test failing if not local db Jul 3, 2023
@gabrielmbmb gabrielmbmb force-pushed the fix/unit_test_failing_if_not_local_db branch from fcd75ab to c12277a Compare July 3, 2023 14:32
@codecov
Copy link

codecov bot commented Jul 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.04 ⚠️

Comparison is base (faed3fe) 90.31% compared to head (853f067) 90.27%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3307      +/-   ##
===========================================
- Coverage    90.31%   90.27%   -0.04%     
===========================================
  Files          234      234              
  Lines        12642    12642              
===========================================
- Hits         11417    11413       -4     
- Misses        1225     1229       +4     
Impacted Files Coverage Δ
src/argilla/server/server.py 86.06% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@frascuchon frascuchon left a comment

Choose a reason for hiding this comment

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

Once we have this working, we should remove alembic migrations in CI pipeline: Here and here

@frascuchon frascuchon self-requested a review July 3, 2023 17:30
@frascuchon frascuchon merged commit 384a69e into develop Jul 3, 2023
@frascuchon frascuchon deleted the fix/unit_test_failing_if_not_local_db branch July 3, 2023 19:19
alvarobartt pushed a commit that referenced this pull request Jul 4, 2023
# Description

The API startup event was using the
`argilla.server.database.get_async_db` function to get a DB session to
check if the default argilla user exists. We were overriding the
`get_async_db` dependency for the API endpoints, but we were not mocking
the function when being used from the API startup, and therefore the
function was returning a session to the local sqlite DB
(`$HOME/.argilla/argilla.db`). If the sqlite local db file didn't exist
and the migrations hadn't been applied, then a `sqlalchemy.errors.
OperationalError` was being raised as the `User` table didn't exist.

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

Running the tests without the `$HOME/.argilla/argilla.db` file doesn't
raise an exception anymore.

**Checklist**

- [ ] I added relevant documentation
- [x] follows the style guidelines of this project
- [x] I did a self-review of my code
- [ ] I made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK)
(see text above)
- [x] I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)

---------

Co-authored-by: frascuchon <francis@argilla.io>
leiyre pushed a commit that referenced this pull request Jul 4, 2023
* develop:
  refactor: add `HuggingFaceDatasetMixIn` under `integrations` (#3326)
  feat: add list user workspaces endpoint (#3308)
  ci: Stop linking issues to team work project
  chore: add missing `greenlet` dependency in `server` extra (#3330)
  fix: unit test failing if not local db (#3307)
  ci: Optimize build + test pipeline (#3300)
  refactor: simplify old bulk endpoints to avoid create datasets if does not exists (#3306)
  📝 Update doc site link (#3299)
  🚑 Fix dependencies (#3302)
  feat: migrate to async SQLAlchemy engine (#3162)
leiyre pushed a commit that referenced this pull request Jul 5, 2023
* develop:
  fix: return all workspaces in system for owner users (#3343)
  fix: `rg.init` with argilla user using quickstart images raise an unexpected error (#3341)
  feat: add `Suggestion` endpoints (#3304)
  feat: add `list_user_workspaces` and `User.workspaces` property (#3334)
  refactor: add `HuggingFaceDatasetMixIn` under `integrations` (#3326)
  feat: add list user workspaces endpoint (#3308)
  ci: Stop linking issues to team work project
  chore: add missing `greenlet` dependency in `server` extra (#3330)
  docs: update developer docs (#3314)
  Docs/3312 docs 112 is not building correctly (#3313)
  fix: unit test failing if not local db (#3307)
  ci: Optimize build + test pipeline (#3300)
  refactor: simplify old bulk endpoints to avoid create datasets if does not exists (#3306)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants