Skip to content

Commit

Permalink
fix profile swap functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Aug 7, 2022
1 parent f15b308 commit c272868
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .changes/0.6.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.6.2 - 2022-08-06
### Fixed
* Fixed profile swapping functionality
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


## 0.6.2 - 2022-08-06
### Fixed
* Fixed profile swapping functionality

## 0.6.1 - 2022-08-06
### Added
* Added 2 RSS feeds to the bottom for easy access reading 🤓
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbt-osmosis"
version = "0.6.1"
version = "0.6.2"
description = "This package exposes an interactive workbench for dbt modelling and serves to cascadingly populate column level documentation, build & conform schema files, and audit coverage."
authors = ["z3z1ma <[email protected]>"]
license = "Apache 2.0"
Expand Down
23 changes: 9 additions & 14 deletions src/dbt_osmosis/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import hashlib
import os
import sys
from collections import OrderedDict
Expand All @@ -10,12 +9,16 @@
import pandas as pd
import pandas_profiling
import streamlit as st
from dbt.contracts.graph import parsed
from dbt.exceptions import CompilationException, DatabaseException, RuntimeException
from streamlit_ace import THEMES, st_ace
from streamlit_pandas_profiling import st_profile_report

from dbt_osmosis.core.osmosis import DEFAULT_PROFILES_DIR, DbtOsmosis, get_raw_profiles
from dbt_osmosis.core.osmosis import (
DEFAULT_PROFILES_DIR,
DbtOsmosis,
MemoContainer,
get_raw_profiles,
)

st.set_page_config(page_title="dbt-osmosis Workbench", page_icon="🌊", layout="wide")
state = st.session_state
Expand Down Expand Up @@ -164,17 +167,9 @@
state.setdefault(PIVOT_LAYOUT, False)


def hash_parsed_node(node: parsed.ParsedModelNode) -> str:
return hashlib.md5(node.raw_sql.encode("utf-8")).hexdigest()


def hash_compiled_node(node: parsed.ParsedModelNode):
return hashlib.md5(node.raw_sql.encode("utf-8")).hexdigest()


def inject_dbt(change_target: Optional[str] = None):
"""Parse dbt project and load context var"""
if DBT not in state:
if DBT not in state or change_target:
dbt_ctx = DbtOsmosis(
project_dir=state[PROJ_DIR],
profiles_dir=state[PROF_DIR],
Expand All @@ -183,7 +178,6 @@ def inject_dbt(change_target: Optional[str] = None):
else:
dbt_ctx: DbtOsmosis = state[DBT]
dbt_ctx.rebuild_dbt_manifest(reset=True)

state[DBT] = dbt_ctx
return True

Expand Down Expand Up @@ -348,14 +342,15 @@ def convert_profile_report_to_html(profile: pandas_profiling.ProfileReport) -> s


if ctx.profile.target_name != state[TARGET_PROFILE]: # or state[DBT_DO_RELOAD]:
# TODO: vet the effectiveness of this re-injection
print("Reloading dbt project...")
with notificationContainer:
ctx.profile.target_name = state[TARGET_PROFILE]
ctx.config.target_name = state[TARGET_PROFILE]
with st.spinner("Reloading dbt... ⚙️"):
inject_dbt(state[TARGET_PROFILE])
# state[RAW_SQL] += " "
state[COMPILED_SQL] = compile_sql(state[RAW_SQL])
MemoContainer._MEMO = {}
st.experimental_rerun()


Expand Down
10 changes: 6 additions & 4 deletions src/dbt_osmosis/core/osmosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
from dbt_osmosis.core.log_controller import logger


def memoize_get_rendered(function):
memo = {}
class MemoContainer:
_MEMO = {}


def memoize_get_rendered(function):
def wrapper(
string: str,
ctx: Dict[str, Any],
Expand All @@ -72,12 +74,12 @@ def wrapper(
if capture_macros == True and node is not None:
# Now the node is important, cache mutated node
v += node.name
rv = memo.get(v)
rv = MemoContainer._MEMO.get(v)
if rv is not None:
return rv
else:
rv = function(string, ctx, node, capture_macros, native)
memo[v] = rv
MemoContainer._MEMO[v] = rv
return rv

return wrapper
Expand Down

0 comments on commit c272868

Please sign in to comment.