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

Extract _get_op_def_compute_fn into wrap_source_asset_observe_fn_in_op_compute_fn #16618

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

schrockn
Copy link
Member

@schrockn schrockn commented Sep 19, 2023

Summary & Motivation

This is a simple refactoring so that I can use this function to implement #16620

How I Tested These Changes

BK

@@ -50,10 +50,87 @@
from dagster._utils.merger import merge_dicts
from dagster._utils.warnings import disable_dagster_warnings

# getting the following error
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smackesey do you have any idea why ruff was firing this error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume if you uncomment [1] and [2] things should work - ruff just wants you to import in the TYPE_CHECKING block if you only use the type as a typehint like in [2]

its unclear to me if [1] is part of the error message you got for a import no longer present, or if you had [1] and commented it out and put the error above it

Comment on lines 55 to 58
# if TYPE_CHECKING:
# from dagster._core.definitions.decorators.op_decorator import (
# DecoratedOpFunction,
# )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[1]

def wrap_source_asset_observe_fn_in_op_compute_fn(
source_asset: "SourceAsset",
):
# ) -> "DecoratedOpFunction":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[2]

@@ -50,10 +50,87 @@
from dagster._utils.merger import merge_dicts
from dagster._utils.warnings import disable_dagster_warnings

# getting the following error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume if you uncomment [1] and [2] things should work - ruff just wants you to import in the TYPE_CHECKING block if you only use the type as a typehint like in [2]

its unclear to me if [1] is part of the error message you got for a import no longer present, or if you had [1] and commented it out and put the error above it

@schrockn schrockn force-pushed the source-asset-wrapping-1 branch from 5aabb85 to 4e8484e Compare September 20, 2023 03:42
@schrockn schrockn force-pushed the source-asset-wrapping-2 branch from 3df7ddc to c1afec3 Compare September 20, 2023 03:42
@schrockn schrockn force-pushed the source-asset-wrapping-1 branch from 4e8484e to 5f71dbf Compare September 20, 2023 20:36
Base automatically changed from source-asset-wrapping-1 to master September 20, 2023 21:19
…p_compute_fn

This refactoring will be useful in a subsequent PR

fix type hecking
@schrockn schrockn force-pushed the source-asset-wrapping-2 branch from c1afec3 to 4354aa0 Compare September 20, 2023 21:20
@schrockn schrockn merged commit 4d3369a into master Sep 21, 2023
@schrockn schrockn deleted the source-asset-wrapping-2 branch September 21, 2023 13:30
schrockn added a commit that referenced this pull request Sep 21, 2023
schrockn added a commit that referenced this pull request Sep 21, 2023
…_fn_in_op_compute_fn (#16618)" (#16688)

## Summary & Motivation

This caused bugs caught in manual testing:

```
Could not load location dagster_test.toys.repo to check for sensors due to the following error: TypeError: 'staticmethod' object is not callable

Stack Trace:
  File "/Users/johann/dagster/python_modules/dagster/dagster/_grpc/server.py", line 295, in __init__
    self._loaded_repositories: Optional[LoadedRepositories] = LoadedRepositories(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_grpc/server.py", line 139, in __init__
    loadable_targets = get_loadable_targets(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_grpc/utils.py", line 47, in get_loadable_targets
    else loadable_targets_from_python_module(module_name, working_directory)
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/workspace/autodiscovery.py", line 35, in loadable_targets_from_python_module
    module = load_python_module(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/code_pointer.py", line 135, in load_python_module
    return importlib.import_module(module_name)
  File "/Users/johann/.pyenv/versions/3.9.10/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/johann/dagster/python_modules/dagster-test/dagster_test/toys/repo.py", line 201, in <module>
    def data_versions_repository():
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/decorators/repository_decorator.py", line 405, in repository
    return _Repository()(definitions_fn)
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/decorators/repository_decorator.py", line 161, in __call__
    else CachingRepositoryData.from_list(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data.py", line 346, in from_list
    return build_caching_repository_data_from_list(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data_builder.py", line 195, in build_caching_repository_data_from_list
    for job_def in get_base_asset_jobs(
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/assets_job.py", line 76, in get_base_asset_jobs
    for observable in [sa for sa in source_assets if sa.is_observable]:
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/assets_job.py", line 76, in <listcomp>
    for observable in [sa for sa in source_assets if sa.is_observable]:
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/source_asset.py", line 256, in is_observable
    return self.node_def is not None
  File "/Users/johann/dagster/python_modules/dagster/dagster/_core/definitions/source_asset.py", line 270, in node_def
    compute_fn=wrap_source_asset_observe_fn_in_op_compute_fn(self),
```

Reverting for now


## How I Tested These Changes

BK
schrockn added a commit that referenced this pull request Sep 21, 2023
…_observe_fn_in_op_compute_fn (#16618)" (#16688)"

This reverts commit e4337b9.
schrockn added a commit that referenced this pull request Sep 21, 2023
…p_compute_fn (Take two) (#16699)

## Summary & Motivation

This is another shot at #16618 which was reverted in #16688 after @johannkm  discovered a bug.

It turns out I had spuriously left a `@staticmethod` decoration on wrap_source_asset_observe_fn_in_op_compute_fn
which worked fine both locally and in CI. This because this only worked in Python 3.10 and later.

https://docs.python.org/3/whatsnew/3.10.html#other-language-changes

```
Static methods (@staticmethod) and class methods (@classmethod) now inherit the method attributes 
(__module__, __name__, __qualname__, __doc__, __annotations__) and have a new __wrapped__ 
attribute. Moreover, static methods are now callable as regular functions.
```

We only run 3.10 in most CI now for cost control. However, sometimes we pay the iron price for this optimization.

## How I Tested These Changes

Load original PR locally in python 3.9. Confirm error on original PR. Apply this patch. See no error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants