Skip to content

Commit

Permalink
Merge branch 'master' of github.com:owid/etl into add-daily-calories-…
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
pabloarosado committed May 27, 2024
2 parents 931ce73 + ceff3c0 commit 704afce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/wizard/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def name(self) -> str:
return "local"
elif self.env_type_id == "staging":
return f"{self.conf.DB_HOST}"
raise ValueError("Unknown env_type_id")
raise ValueError(f"Unknown env_type_id (DB_NAME/DB_USER={self.conf.DB_NAME}/{self.conf.DB_USER})")

@property
def base_site(self) -> str | None:
Expand Down
8 changes: 5 additions & 3 deletions etl/grapher_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pymysql import IntegrityError
from sqlalchemy import text
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session

from etl.db import get_engine, read_sql
from etl.files import checksum_str
Expand Down Expand Up @@ -312,12 +313,12 @@ def _get_entities_from_db(

def _get_and_create_entities_in_db(countries: Set[str], engine: Engine | None = None) -> Dict[str, int]:
engine = engine or get_engine()
with engine.connect() as con:
with Session(engine) as session:
log.info("Creating entities in DB", countries=countries)
out = {}
for name in countries:
try:
con.execute(
session.execute(
text(
"""
INSERT INTO entities
Expand All @@ -328,12 +329,13 @@ def _get_and_create_entities_in_db(countries: Set[str], engine: Engine | None =
),
{"name": name},
)
session.commit()
except IntegrityError:
# If another process inserted the same entity before us, we can
# safely ignore the error and fetch the ID
pass

row = con.execute(
row = session.execute(
text(
"""
SELECT id FROM entities
Expand Down

0 comments on commit 704afce

Please sign in to comment.