Skip to content

Commit

Permalink
Metabase 50 compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Jun 12, 2024
1 parent b2286c0 commit 2dfbab5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
4 changes: 4 additions & 0 deletions dbtmetabase/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ 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
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

0 comments on commit 2dfbab5

Please sign in to comment.