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

Metabase 50 support #257

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ install: build
.PHONY: install

sandbox-up:
( cd sandbox && docker-compose up --build --attach app )
( cd sandbox && docker compose up --build --attach app )
.PHONY: sandbox-up

sandbox-down:
( cd sandbox && docker-compose down )
( cd sandbox && docker compose down )
.PHONY: sandbox-up

sandbox-models:
( source sandbox/.env && python3 -m dbtmetabase models \
( . sandbox/.env && python3 -m dbtmetabase models \
--manifest-path sandbox/target/manifest.json \
--metabase-url http://localhost:$$MB_PORT \
--metabase-username $$MB_USER \
Expand All @@ -86,7 +86,7 @@ sandbox-models:
sandbox-exposures:
rm -rf sandbox/models/exposures
mkdir -p sandbox/models/exposures
( source sandbox/.env && python3 -m dbtmetabase exposures \
( . sandbox/.env && python3 -m dbtmetabase exposures \
--manifest-path sandbox/target/manifest.json \
--metabase-url http://localhost:$$MB_PORT \
--metabase-username $$MB_USER \
Expand All @@ -95,7 +95,7 @@ sandbox-exposures:
--output-grouping collection \
--verbose )

( source sandbox/.env && cd sandbox && \
( . sandbox/.env && cd sandbox && \
POSTGRES_HOST=localhost \
POSTGRES_PORT=$$POSTGRES_PORT \
POSTGRES_USER=$$POSTGRES_USER \
Expand Down
7 changes: 7 additions & 0 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def find_user(self, uid: str) -> Optional[Mapping]:
if error.response.status_code == 404:
_logger.warning("User '%s' not found", uid)
return None
elif (
error.response.status_code == 400
and "internal user" in error.response.text
):
# Since X.50.0 fetching internal user raises 400 Not able to modify the internal user
_logger.warning("User '%s' is internal", uid)
return None
raise

def update_table(self, uid: str, body: Mapping) -> Mapping:
Expand Down
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ black>=23.11.0
isort>=5.12.0
pylint>=3.0.2
mypy>=1.7.1
molot>=1.0.0,<1.1.0
dbt-postgres>=1.7.4,<2.0.0
molot~=1.0.0
dbt-postgres~=1.7.16
types-requests
types-PyYAML
4 changes: 1 addition & 3 deletions sandbox/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

name: dbt-metabase-sandbox

services:
Expand All @@ -22,7 +20,7 @@ services:
restart: always

metabase:
image: metabase/metabase:latest
image: metabase/metabase:v0.50.0
environment:
- MB_SETUP_TOKEN=${MB_SETUP_TOKEN:-}
ports:
Expand Down
46 changes: 39 additions & 7 deletions sandbox/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def dbt_run():
shell("dbt run --profiles-dir .")


def _session_headers():
session_id = requests.post(
url=f"http://{MB_HOST}:{MB_PORT}/api/session",
json={"username": MB_USER, "password": MB_PASSWORD},
timeout=10,
).json()["id"]

return {"X-Metabase-Session": session_id}


@target(description="set up Metabase user and database")
def metabase_setup():
requests.post(
Expand Down Expand Up @@ -76,16 +86,38 @@ def metabase_setup():
timeout=10,
).raise_for_status()

requests.post(
url=f"http://{MB_HOST}:{MB_PORT}/api/database",
headers=_session_headers(),
json={
"engine": "postgres",
"name": POSTGRES_DB,
"details": {
"host": POSTGRES_HOST,
"port": POSTGRES_PORT,
"dbname": POSTGRES_DB,
"user": POSTGRES_USER,
"password": POSTGRES_PASSWORD,
"schema-filters-type": "all",
"ssl": False,
"tunnel-enabled": False,
"advanced-options": False,
},
"is_on_demand": False,
"is_full_sync": True,
"is_sample": False,
"cache_ttl": None,
"refingerprint": False,
"auto_run_queries": True,
"schedules": {},
},
timeout=10,
).raise_for_status()


@target(description="add mock content to Metabase")
def metabase_content():
session_id = requests.post(
url=f"http://{MB_HOST}:{MB_PORT}/api/session",
json={"username": MB_USER, "password": MB_PASSWORD},
timeout=10,
).json()["id"]

headers = {"X-Metabase-Session": session_id}
headers = _session_headers()

database_id = ""
databases = requests.get(
Expand Down
Loading