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

[WIP] Allow reloading database connection #3827

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Nov 21, 2023

Marked as draft for discussion.

Inspired by a Slack community question, I wanted to see what it would look like to allow changing databases mid-Python session by calling a fo.reload() method.

I believe this PR is fully functional for programmatic usage, but there are a couple snags when using the App:

  • The App runs in a subprocess which currently re-reads its fo.config from environment variables, so you have to change database via os.environ rather than just editing fo.config in order for launch_app() to work after the database change in the example below
  • If I launch_app() before and after the database change, the second App does not connect to the new database
import os
import fiftyone as fo
import fiftyone.zoo as foz

# do stuff with default database
print(fo.list_datasets())

#
# Change database
#

"""
os.environ["FIFTYONE_DATABASE_URI"] = "mongodb://localhost:12345"
os.environ["FIFTYONE_DATABASE_DIR"] = "/path/to/new/db"
fo.reload(hard=True)
"""

fo.config.database_uri = "mongodb://localhost:12345"
fo.config.database_dir = "/path/to/new/db"
fo.reload()

# do stuff with new database
print(fo.list_datasets())
dataset = foz.load_zoo_dataset("quickstart")

# Only works with `fo.reload(hard=True)` since subprocess reads config from env vars
session = fo.launch_app(dataset)

@brimoor brimoor added the feature Work on a feature request label Nov 21, 2023
@brimoor brimoor requested a review from a team November 21, 2023 15:34
@brimoor brimoor self-assigned this Nov 21, 2023
Copy link

codecov bot commented Nov 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8c018ed) 15.85% compared to head (6a7a6e9) 15.85%.
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3827   +/-   ##
========================================
  Coverage    15.85%   15.85%           
========================================
  Files          731      731           
  Lines        81886    81886           
  Branches      1093     1093           
========================================
  Hits         12987    12987           
  Misses       68899    68899           
Flag Coverage Δ
app 15.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaixi-wang
Copy link
Contributor

unsure how/if changing the mongo connection would affect pymongo, but through aliased connections (https://docs.mongoengine.org/guide/connecting.html#switch-database), you could maybe hack a way to overcome the snags you mentioned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants