Skip to content

Commit

Permalink
Proper handling of sqlalchemy database sessions in fastapi and celery (
Browse files Browse the repository at this point in the history
…#522)

* Initial work on making API endpoint for accessing role_mappings/metadat

* Ruff checks

* Major refactor to move towards explicit sessions in sqlalchemy

* Getting celery tasks to use same database session

* Disable thread check escape for proper testing

* Black formatting

* Remove echo statement

* Fixing tests

* Ensure that celery db is initialized and fix missing call

* Do not check same thread in tests

* Adding better debugging

* Pinning conda version until 23.7.X issues are resolved

See mamba-org/mamba#2715
  • Loading branch information
costrouc committed Aug 4, 2023
1 parent 5507732 commit bfb5b89
Show file tree
Hide file tree
Showing 24 changed files with 625 additions and 534 deletions.
24 changes: 7 additions & 17 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict, Any, Optional, Union
from typing import List, Dict, Any
import re

from sqlalchemy import func, null, or_, distinct
Expand Down Expand Up @@ -49,8 +49,8 @@ def create_namespace(db, name: str):
def update_namespace(
db,
name: str,
metadata_: Union[Optional[Dict], None] = None,
role_mappings: Union[Optional[Dict[str, List[str]]], None] = None,
metadata_: Dict[str, Any] = None,
role_mappings: Dict[str, List[str]] = None,
):

namespace = get_namespace(db, name)
Expand All @@ -63,24 +63,22 @@ def update_namespace(
if role_mappings is not None:

# deletes all the existing role mappings ...
for rm in namespace.roles_mappings:
for rm in namespace.role_mappings:
db.delete(rm)

# ... before adding all the new ones
mappings_orm = []
for entity, roles in role_mappings.items():
for r in roles:

for role in roles:
mapping_orm = orm.NamespaceRoleMapping(
namespace_id=namespace.id,
namespace=namespace,
entity=entity,
role=r,
role=role,
)

mappings_orm.append(mapping_orm)

namespace.roles_mappings = mappings_orm
namespace.role_mappings = mappings_orm

db.commit()

Expand Down Expand Up @@ -230,14 +228,6 @@ def get_specification(db, sha256: str):
return db.query(orm.Specification).filter(*filters).first()


def post_specification(conda_store, specification, namespace=None):
return conda_store.register_environment(specification, namespace, force=True)


def post_solve(conda_store, specification: schema.CondaSpecification):
return conda_store.register_solve(specification)


def create_solve(db, specification_id: int):
solve = orm.Solve(specification_id=specification_id)
db.add(solve)
Expand Down
Loading

0 comments on commit bfb5b89

Please sign in to comment.