Skip to content

Commit

Permalink
Fix merge conflicts with main
Browse files Browse the repository at this point in the history
Signed-off-by: Donny Peeters <[email protected]>
  • Loading branch information
Donnype committed Nov 9, 2023
1 parent ffad97f commit cb45277
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
18 changes: 1 addition & 17 deletions bytes/bytes/database/sql_meta_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,7 @@ def save_raw(self, raw: RawData) -> uuid.UUID:
def get_raw(self, query_filter: RawDataFilter) -> List[RawDataMeta]:
logger.debug("Querying raw data: %s", query_filter.json())
query = self.session.query(RawFileInDB)

if query_filter.boefje_meta_id:
query = query.filter(RawFileInDB.boefje_meta_id == str(query_filter.boefje_meta_id))

if query_filter.organization:
query = query.join(BoefjeMetaInDB).filter(BoefjeMetaInDB.organization == query_filter.organization)

if query_filter.normalized:
query = query.join(NormalizerMetaInDB, isouter=False)

if query_filter.normalized is False: # it can also be None, in which case we do not want a filter
query = query.join(NormalizerMetaInDB, isouter=True).filter(NormalizerMetaInDB.id.is_(None))

if query_filter.mime_types:
query = query.filter(RawFileInDB.mime_types.contains([m.value for m in query_filter.mime_types]))

query = query.offset(query_filter.offset).limit(query_filter.limit)
query = query_filter.apply(query)

return [to_raw_meta(raw_file_in_db) for raw_file_in_db in query]

Expand Down
16 changes: 4 additions & 12 deletions bytes/bytes/repositories/meta_repository.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List, Optional, Type
from typing import Dict, List, Optional, Type
from uuid import UUID

from pydantic import BaseModel, Field, root_validator
from pydantic import BaseModel, Field
from sqlalchemy.orm import Query

from bytes.database.db_models import BoefjeMetaInDB, NormalizerMetaInDB, RawFileInDB
Expand Down Expand Up @@ -35,19 +35,11 @@ class RawDataFilter(BaseModel):
limit: Optional[int] = 1
offset: Optional[int] = 0

@root_validator(pre=False)
def either_organization_or_boefje_meta_id( # pylint: disable=no-self-argument
cls, values: Dict[str, Any]
) -> Dict[str, Any]:
if values.get("organization") or values.get("boefje_meta_id"):
return values

raise ValueError("boefje_meta_id and organization cannot both be None.")

def apply(self, query: Query) -> Query:
if self.boefje_meta_id:
query = query.filter(RawFileInDB.boefje_meta_id == str(self.boefje_meta_id))
else:

if self.organization:
query = query.join(BoefjeMetaInDB).filter(BoefjeMetaInDB.organization == self.organization)

if self.normalized:
Expand Down

0 comments on commit cb45277

Please sign in to comment.