-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove the duplicate get_context_modules #1996
Conversation
Wow, that's crazy @Fokko, I was just preparing a PR to do the exact same thing as you (add the ability to inject custom modules), also came across this duplicated code and then I spotted your PR. Do you have a follow-up PR for injecting modules? If not, I'll merge your code first to do my PR :) |
247e2ce
to
a1ff0a4
Compare
Good to see that I'm not the only one :-) I'd like to do some counts, and send them to an external system. I'm currently exploring two directions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @Fokko - Funny story, I actually have a WIP branch that also fixes this, but it's not ready to go for unrelated reasons.
I'm happy to merge this standalone, some very minor feedback before I kick off the tests and we get this merged :)
core/dbt/context/base.py
Outdated
'pytz': get_pytz_module_context(), | ||
'datetime': get_datetime_module_context(), | ||
} | ||
CONTEXT_MODULES: Dict[str, Dict[str, Any]] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep this as a global function that returns a dict, instead of a global dict? I have a good reason and a bad/lazy reason:
- I don't want us to share the same dict into every jinja environment. I think jinja does a shallow copy of the context and I want to build a fresh one every time we generate a context, since dicts are mutable.
- I want to minimize merge conflicts with my other branch that makes the same change :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've reverted the change.
a1ff0a4
to
cf41203
Compare
I've stopped pursuing implementing a custom Python function, and went with https://github.com/fishtown-analytics/dbt-event-logging/ instead. This does everything I need for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've kicked off the test suite, I think this is good to go. Thanks for your contribution to dbt!
@Fokko sorry about this, but mypy is failing, I think before this function wasn't annotated so it wasn't inspected. Can you add a |
@beckjake Sure, I've added the exception. |
While looking at the code, and figuring out how to inject custom modules, I've stumbled upon some duplicate code. Besides that, I also took the liberty of adding annotations.