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

Use a separate cursor field when paginating through the asset catalog #23511

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

gibsondan
Copy link
Member

Summary:
The frontend passes in an ID which may have been emitted by get_unique_asset_id, which prepends a prefix before the path starts. Fix the asset key normalizer to account for that case.

Test Plan: New test case

Summary & Motivation

How I Tested These Changes

@gibsondan gibsondan requested review from prha and alangenfeld August 8, 2024 17:06
@gibsondan gibsondan changed the title Correctly handle asset Ids in asset pagination Correctly handle graphql asset IDs in asset pagination Aug 8, 2024
Comment on lines 81 to 83
# Filter out the initial location:repository from the id if present
# Assumes that '[' will never be in an asset key string after the initial character
cursor_string = cursor_string[cursor_string.rfind("[") :]
Copy link
Member

Choose a reason for hiding this comment

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

should we be more defensive here and check for str:str[ before mutating? just thinking about how this behaves if assumptions are invalid in the future

Copy link
Member Author

Choose a reason for hiding this comment

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

the thing that I ran into here is that these are location and repository names and we don't seem to restrict "." in those names :/ (at least i can create a code location that starts with a "." locally)

Copy link
Member Author

Choose a reason for hiding this comment

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

Similarly we appear to allow "[" in location names which is why I grabbed the last one

Copy link
Member

Choose a reason for hiding this comment

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

Assumes that '[' will never be in an asset key string after the initial character

do we guard against this else where ? I was able to do

>>> from dagster import AssetKey
>>> AssetKey('foo[a]')
AssetKey(['foo[a]'])

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I tried to use it in an asset definition and got

  File "/Users/dgibson/dagster/hi.py", line 4, in <module>
    @asset(name="[hello")
     ^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/decorators/asset_decorator.py", line 285, in inner
    return create_assets_def_from_fn_and_decorator_args(args, fn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/decorators/asset_decorator.py", line 482, in create_assets_def_from_fn_and_decorator_args
    return builder.create_assets_definition()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/decorators/decorator_assets_definition_builder.py", line 550, in create_assets_definition
    node_def=self.create_op_definition(),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/decorators/decorator_assets_definition_builder.py", line 531, in create_op_definition
    return _Op(
           ^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/decorators/op_decorator.py", line 125, in __call__
    op_def = OpDefinition.dagster_internal_init(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/op_definition.py", line 206, in dagster_internal_init
    return OpDefinition(
           ^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/decorator_utils.py", line 203, in wrapped_with_pre_call_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/op_definition.py", line 183, in __init__
    super(OpDefinition, self).__init__(
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/node_definition.py", line 54, in __init__
    self._name = check_valid_name(name)
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/utils.py", line 93, in check_valid_name
    check_valid_chars(name)
  File "/Users/dgibson/dagster/python_modules/dagster/dagster/_core/definitions/utils.py", line 101, in check_valid_chars
    raise DagsterInvalidDefinitionError(

I should double check that we also don't let you materialize an asset with that key without it being a definition

Copy link
Member

Choose a reason for hiding this comment

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

maybe something like https://regex101.com/r/RDXNfK/2 if we want to do regex approach

prha
prha previously approved these changes Aug 8, 2024
@gibsondan gibsondan requested review from alangenfeld and prha August 8, 2024 18:50
@gibsondan gibsondan dismissed prha’s stale review August 8, 2024 18:50

take 2 - avoid IDs entirely and use a cursor

@gibsondan gibsondan force-pushed the nodedefnamefix branch 2 times, most recently from 62985e3 to 377442a Compare August 8, 2024 18:51
@gibsondan gibsondan requested review from salazarm and jmsanders August 8, 2024 18:53
Copy link

github-actions bot commented Aug 8, 2024

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-oh4evwm2o-elementl.vercel.app
https://nodedefnamefix.core-storybook.dagster-docs.io

Built with commit 175b69f.
This pull request is being automatically deployed with vercel-action

@gibsondan gibsondan changed the title Correctly handle graphql asset IDs in asset pagination Use a separate cursor field when paginating through the asset catalog Aug 8, 2024
Summary:
The frontend passes in an ID which may have been emitted by get_unique_asset_id, which prepends a prefix before the path starts. Fix the asset key normalizer to account for that case.

Test Plan: New test case

hi
@gibsondan gibsondan merged commit 15fa553 into master Aug 8, 2024
1 of 2 checks passed
@gibsondan gibsondan deleted the nodedefnamefix branch August 8, 2024 19:46
gibsondan added a commit that referenced this pull request Aug 8, 2024
…#23511)

Summary:
The frontend passes in an ID which may have been emitted by
get_unique_asset_id, which prepends a prefix before the path starts. Fix
the asset key normalizer to account for that case.

Test Plan: New test case

## Summary & Motivation

## How I Tested These Changes
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.

4 participants