Skip to content

Commit

Permalink
Fix wrong column used in datapoint filter (#51)
Browse files Browse the repository at this point in the history
* attempt to fix nasty count bug

* fix incorrect column used for join in filter

* revert count function
  • Loading branch information
meksor authored Feb 29, 2024
1 parent 6a523d3 commit 19ba8b4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
7 changes: 6 additions & 1 deletion ixmp4/conf/logging/server.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[loggers]
keys = root,sqlalchemy,fastapi,httpx,uvicorn,access
keys = root,sqlalchemy,fastapi,httpx,uvicorn,access,watchfiles

[handlers]
keys = access,debug,error,console
Expand All @@ -13,6 +13,11 @@ level = NOTSET
handlers = debug,error
qualname = sqlalchemy

[logger_watchfiles]
level = ERROR
handlers = error,debug
qualname = watchfiles.main

[logger_fastapi]
level = NOTSET
handlers = debug,error,console
Expand Down
4 changes: 1 addition & 3 deletions ixmp4/data/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ def count(
**kwargs,
) -> int:
_exc = self.select(
_exc=db.select(db.func.count(self.model_class.id.distinct())).select_from(
self.model_class
),
_exc=db.select(db.func.count(self.model_class.id.distinct())),
**kwargs,
)
return self.session.execute(_exc).scalar_one()
Expand Down
2 changes: 1 addition & 1 deletion ixmp4/data/db/iamc/datapoint/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def join(self, exc, session):
if not utils.is_joined(exc, Run):
exc = exc.join(Run, TimeSeries.run)
if not utils.is_joined(exc, Scenario):
exc = exc.join(Scenario, onclause=Run.model__id == Scenario.id)
exc = exc.join(Scenario, onclause=Run.scenario__id == Scenario.id)
return exc


Expand Down
31 changes: 10 additions & 21 deletions ixmp4/data/db/iamc/datapoint/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import pandas as pd
import pandera as pa
from pandera.typing import DataFrame, Series
from sqlalchemy import select
from sqlalchemy.orm import Bundle

from ixmp4 import db
from ixmp4.core.decorators import check_types
Expand Down Expand Up @@ -109,36 +107,27 @@ def join_auth(self, exc: db.sql.Select) -> db.sql.Select:
return exc

def select_joined_parameters(self, join_runs=False):
_bundle = []
bundle = []
if join_runs:
_bundle.extend(
bundle.extend(
[
Bundle("Model", Model.name.label("model")),
Bundle("Scenario", Scenario.name.label("scenario")),
Bundle("Run", Run.version),
Model.name.label("model"),
Scenario.name.label("scenario"),
Run.version.label("version"),
]
)

_bundle.extend(
bundle.extend(
[
Bundle(
"Region",
Region.name.label("region"),
),
Bundle(
"Unit",
Unit.name.label("unit"),
),
Bundle(
"Variable",
Variable.name.label("variable"),
),
Region.name.label("region"),
Unit.name.label("unit"),
Variable.name.label("variable"),
self.bundle,
]
)

_exc = (
select(*_bundle)
db.select(*bundle)
.join(
TimeSeries, onclause=self.model_class.time_series__id == TimeSeries.id
)
Expand Down
2 changes: 1 addition & 1 deletion ixmp4/server/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .middleware import RequestSizeLoggerMiddleware, RequestTimeLoggerMiddleware
from .optimization import indexset, scalar

v1 = FastAPI()
v1 = FastAPI(servers=[{"url": "/v1", "description": "v1"}])

if settings.mode == "debug":
v1.add_middleware(RequestSizeLoggerMiddleware)
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ documentation = "https://docs.ece.iiasa.ac.at/projects/ixmp4"

[tool.poetry.dependencies]
PyJWT = "^2.4.0"
SQLAlchemy = {extras = ["mypy"], version = "^2.0.25"}
SQLAlchemy = { extras = ["mypy"], version = "^2.0.25" }
SQLAlchemy-Utils = "^0.41.1"
alembic = "^1.13.1"
dask = "^2024.1.1"
fastapi = "^0.109.0"
httpx = {extras = ["http2"], version = "^0.26.0"}
httpx = { extras = ["http2"], version = "^0.26.0" }
openpyxl = "^3.0.9"
pandas = "~2.1.2"
pandera = "^0.18.0"
Expand All @@ -32,7 +32,7 @@ python-dotenv = "^1.0.1"
requests = "^2.27.1"
typer = "^0.9.0"
toml = "^0.10.2"
psycopg = {extras = ["binary"], version = "^3.1.17"}
psycopg = { extras = ["binary"], version = "^3.1.17" }
pydantic-settings = "^2.1.0"
rich = "^13.7.0"

Expand All @@ -51,7 +51,7 @@ optional = true

[tool.poetry.group.server.dependencies]
gunicorn = "^21.2.0"
uvicorn = {extras = ["standard"], version = "^0.27.0.post1"}
uvicorn = { extras = ["standard"], version = "^0.27.0.post1" }

[tool.poetry.group.dev]
optional = true
Expand Down

0 comments on commit 19ba8b4

Please sign in to comment.