Skip to content

Item type and asset type validation in Data and Subscriptions #905

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

Merged
merged 36 commits into from
Apr 7, 2023

Conversation

kevinlacaille
Copy link
Contributor

@kevinlacaille kevinlacaille commented Mar 31, 2023

Related Issue(s):

Closes #877 and #903

Proposed Changes:

For inclusion in changelog (if applicable):

  1. Validated item types in the Data client (get_asset(), and and item types and asset types subscription_request.catalog_source()clients, and consiquently in its CLI commandrequest-catalog`. This allows case insensitivity and a list of valid options of both item types and asset types in both the Data and Subscriptions the CLI.

Not intended for changelog:

  1. Added validation and --help choices for the following CLI functions:
  • subscriptions request-catalog
  • data search-update
  • data asset-download
  • data asset-activate
  • data asset-wait
  1. Added item_type validation to get_asset(), which each asset-* CLI command updated calls.
  2. Added asset_type validation in subscription_request which request-catalog calls.

Diff of User Interface

Old behavior:

planet subscriptions request-catalog \
        --item-types psscene \
        --asset-types not-a-valid-asset-type \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01
{"type": "catalog", "parameters": {"item_types": ["psscene"], "asset_types": ["not-a-valid-asset-type"], "geometry": {"type": "Polygon", "coordinates": [[[7.05322265625, 46.81509864599243], [7.580566406250001, 46.81509864599243], [7.580566406250001, 47.17477833929903], [7.05322265625, 47.17477833929903], [7.05322265625, 46.81509864599243]]]}, "start_time": "2022-01-01T00:00:00Z"}}

New behavior:

planet subscriptions request-catalog \
        --item-types psscene \
        --asset-types not-a-valid-asset-type \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01
Error: asset_type - 'not-a-valid-asset-type' is not one of 'ortho_analytic_8b', 'ortho_analytic_4b', 'ortho_analytic_3b', 'basic_analytic_4b_rpc', 'ortho_analytic_8b_xml', 'ortho_analytic_8b_sr', 'ortho_analytic_4b_xml', 'ortho_visual', 'basic_udm2', 'basic_analytic_4b_xml', 'ortho_udm2', 'basic_analytic_8b_xml', 'basic_analytic_8b', 'ortho_analytic_3b_xml', 'ortho_analytic_4b_sr', 'basic_analytic_4b'.

Old behavior:

planet subscriptions request-catalog \
        --item-types not-a-valid-item-type \
        --asset-types not-a-valid-asset-type \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01
{"type": "catalog", "parameters": {"item_types": ["not-a-valid-item-type"], "asset_types": ["not-a-valid-asset-type"], "geometry": {"type": "Polygon", "coordinates": [[[7.05322265625, 46.81509864599243], [7.580566406250001, 46.81509864599243], [7.580566406250001, 47.17477833929903], [7.05322265625, 47.17477833929903], [7.05322265625, 46.81509864599243]]]}, "start_time": "2022-01-01T00:00:00Z"}}

New behavior:

planet subscriptions request-catalog \                 
        --item-types not-a-valid-item-type \
        --asset-types not-a-valid-asset-type \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01
Usage: planet subscriptions request-catalog [OPTIONS]
Try 'planet subscriptions request-catalog --help' for help.

Error: Invalid value for '--item-types': 'not-a-valid-item-type' is not one of 'MYD09GQ', 'MYD09GA', 'REScene', 'REOrthoTile', 'Sentinel2L1C', 'PSScene', 'SkySatCollect', 'MOD09GA', 'Sentinel1', 'Landsat8L1G', 'MOD09GQ', 'PSOrthoTile', 'SkySatScene'.

Old behavior:

planet subscriptions request-catalog --help     
Usage: planet subscriptions request-catalog [OPTIONS]

  Generate a subscriptions request catalog source description.

Options:
  --item-types TEXT      Item type for requested item ids.  [required]
  --asset-types TEXT     One or more comma-separated asset types.  [required]
  --geometry JSON        Geometry of the area of interest of the subscription
                         that will be used to determine matches. Can be a
                         string, filename, or - for stdin.  [required]
  --start-time DATETIME  Date and time to begin subscription.  [required]
  --end-time DATETIME    Date and time to end subscription.
  --rrule TEXT           iCalendar recurrance rule to specify recurrances.
  --filter JSON          Search filter.  Can be a string, filename, or - for
                         stdin.
  --pretty               Format JSON output.
  --help                 Show this message and exit.

  Valid entries for ITEM_TYPES: Landsat8L1G|Sentinel2L1C|REOrthoTile|MYD09GQ|M
  OD09GA|REScene|MOD09GQ|Sentinel1|MYD09GA|PSScene|PSOrthoTile|SkySatScene|Sky
  SatCollect

New behavior:

planet subscriptions request-catalog --help
Usage: planet subscriptions request-catalog [OPTIONS]

  Generate a subscriptions request catalog source description.

Options:
  --item-types [SkySatScene|Sentinel1|PSScene|MYD09GQ|PSOrthoTile|MYD09GA|Sentinel2L1C|REOrthoTile|MOD09GQ|REScene|MOD09GA|SkySatCollect|Landsat8L1G]
                                  Item type for requested item ids.
                                  [required]
  --asset-types TEXT              One or more comma-separated asset types.
                                  [required]
  --geometry JSON                 Geometry of the area of interest of the
                                  subscription that will be used to determine
                                  matches. Can be a string, filename, or - for
                                  stdin.  [required]
  --start-time DATETIME           Date and time to begin subscription.
                                  [required]
  --end-time DATETIME             Date and time to end subscription.
  --rrule TEXT                    iCalendar recurrance rule to specify
                                  recurrances.
  --filter JSON                   Search filter.  Can be a string, filename,
                                  or - for stdin.
  --pretty                        Format JSON output.
  --help                          Show this message and exit.

Old behavior:

planet data search-update 66722b2c8d184d4f9fb8b8fcf9d1a08c psscene --filter ../jsons_for_tests/filter.json --name "name"
Traceback (most recent call last):
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/specs.py", line 125, in get_match
    match = next(e for e in spec_entries
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/bin/planet", line 33, in <module>
    sys.exit(load_entry_point('planet', 'console_scripts', 'planet')())
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/cli/cmds.py", line 57, in wrapper
    func(*args, **kwargs)
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/cli/cmds.py", line 36, in wrapper
    return asyncio.run(func(*args, **kwargs))
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/kevin.lacaille/.pyenv/versions/3.9.6/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/cli/data.py", line 509, in search_update
    items = await cl.update_search(search_id,
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/clients/data.py", line 240, in update_search
    item_types = [validate_item_type(item) for item in item_types]
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/clients/data.py", line 240, in <listcomp>
    item_types = [validate_item_type(item) for item in item_types]
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/specs.py", line 70, in validate_item_type
    return _validate_field(item_type, supported_item_types, 'item_type')
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/specs.py", line 93, in _validate_field
    value = get_match(value, supported, field_name)
  File "/Users/kevin.lacaille/code/repos/planet/planet-client-python/planet/specs.py", line 128, in get_match
    raise SpecificationException(test_entry, spec_entries, field_name)
planet.specs.SpecificationException: item_type - 'type' is not one of 'REOrthoTile', 'PSScene', 'MOD09GA', 'MYD09GA', 'REScene', 'Landsat8L1G', 'Sentinel2L1C', 'SkySatScene', 'MYD09GQ', 'MOD09GQ', 'PSOrthoTile', 'SkySatCollect', 'Sentinel1'.

New behavior:

planet data search-update 66722b2c8d184d4f9fb8b8fcf9d1a08c psscene --filter ../jsons_for_tests/filter.json --name "name"
{"__daily_email_enabled": false, "_links": {"_self": "https://api.planet.com/data/v1/searches/66722b2c8d184d4f9fb8b8fcf9d1a08c", "results": "https://api.planet.com/data/v1/searches/66722b2c8d184d4f9fb8b8fcf9d1a08c/results"}, "created": "2023-02-09T23:22:15.642226Z", "filter": {"config": [], "type": "AndFilter"}, "id": "66722b2c8d184d4f9fb8b8fcf9d1a08c", "item_types": ["PSScene"], "last_executed": null, "name": "name", "search_type": "saved", "updated": "2023-04-04T18:15:57.490889Z"}

Old behavior:

planet data search-update --help                                                                                        
Usage: planet data search-update [OPTIONS] SEARCH_ID ITEM_TYPES

  Update a saved search with the given search request.

  This function outputs a full JSON description of the updated search,
  optionally pretty-printed.

Options:
  --filter JSON  Filter to apply to search. Can be a json string, filename, or
                 '-' for stdin.  [required]
  --name TEXT    Name of the saved search.  [required]
  --daily-email  Send a daily email when new results are added.
  --pretty       Format JSON output.
  --help         Show this message and exit.

New behavior:

planet data search-update --help
Usage: planet data search-update [OPTIONS] SEARCH_ID ITEM_TYPES

  Update a saved search with the given search request.

  This function outputs a full JSON description of the updated search,
  optionally pretty-printed.

Options:
  --filter JSON  Filter to apply to search. Can be a json string, filename, or
                 '-' for stdin.  [required]
  --name TEXT    Name of the saved search.  [required]
  --daily-email  Send a daily email when new results are added.
  --pretty       Format JSON output.
  --help         Show this message and exit.

  Valid entries for ITEM_TYPES: REOrthoTile|PSScene|MYD09GA|Sentinel1|REScene|
  PSOrthoTile|MYD09GQ|Sentinel2L1C|SkySatCollect|Landsat8L1G|MOD09GQ|SkySatSce
  ne|MOD09GA

Old behavior:

planet data asset-activate psscene 20220101_153358_18_2421 basic_analytic_4b
Error: {"general": [{"message": "The requested item type does not exist."}], "field": {}}

New behavior:

planet data asset-activate psscene 20220101_153358_18_2421 basic_analytic_4b

Old behavior:

planet data asset-activate --help                                                                                   
Usage: planet data asset-activate [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Activate an asset.

Options:
  --help  Show this message and exit.

New behavior:

planet data asset-activate --help                                                                                   
Usage: planet data asset-activate [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Activate an asset.

Options:
  --help  Show this message and exit.

  Valid entries for ITEM_TYPES: MOD09GQ|Sentinel1|PSScene|MYD09GQ|SkySatCollec
  t|MOD09GA|Landsat8L1G|SkySatScene|Sentinel2L1C|PSOrthoTile|REOrthoTile|RESce
  ne|MYD09GA

Old behavior:

planet data asset-wait psscene 20220101_153358_18_2421 basic_analytic_4b    
Error: {"general": [{"message": "The requested item type does not exist."}], "field": {}}

New behavior:

planet data asset-wait psscene 20220101_153358_18_2421 basic_analytic_4b    
00:00 - psscene 20220101_153358_18_2421 basic_analytic_4b - status: active
{'_links': {'_self': 'https://api.planet.com/data/v1/assets/eyJpIjogIjIwMjIwMTAxXzE1MzM1OF8xOF8yNDIxIiwgImMiOiAiUFNTY2VuZSIsICJ0IjogImJhc2ljX2FuYWx5dGljXzRiIiwgImN0IjogIml0ZW0tdHlwZSJ9', 'activate': 'https://api.planet.com/data/v1/assets/eyJpIjogIjIwMjIwMTAxXzE1MzM1OF8xOF8yNDIxIiwgImMiOiAiUFNTY2VuZSIsICJ0IjogImJhc2ljX2FuYWx5dGljXzRiIiwgImN0IjogIml0ZW0tdHlwZSJ9/activate', 'type': 'https://api.planet.com/data/v1/asset-types/basic_analytic_4b'}, '_permissions': ['download'], 'expires_at': '2023-04-04T19:18:27.385219', 'location': 'https://api.planet.com/data/v1/download?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhQnlmbklJcDVWV25kZ3JkOUxfRGNwYm96WERVaTJTTWEyTmZ3bU1Wcm1EZ2VZamxYYlhWT1h4SEVNcThRVElNd255UFhSbUNHUUVSXzRuVnh6TkFFdz09IiwiZXhwIjoxNjgwNjM1OTA3LCJ0b2tlbl90eXBlIjoidHlwZWQtaXRlbSIsIml0ZW1fdHlwZV9pZCI6IlBTU2NlbmUiLCJpdGVtX2lkIjoiMjAyMjAxMDFfMTUzMzU4XzE4XzI0MjEiLCJhc3NldF90eXBlIjoiYmFzaWNfYW5hbHl0aWNfNGIifQ.0bSw6038hWw4pw19LV0jm-iX7v40rozrinJq5r2uFw9E4hS5GNZlnTgBABqflRR7cMZL9NV37RXasaCP06fl4w', 'md5_digest': 'b1173f89f3381950c975dbe433cf116e', 'status': 'active', 'type': 'basic_analytic_4b'}

Old behavior:

planet data asset-wait --help                                                                                           
Usage: planet data asset-wait [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Wait for an asset to be activated.

  Returns when the asset status has reached "activated" and the asset is
  available.

Options:
  --delay INTEGER         Time (in seconds) between polls.
  --max-attempts INTEGER  Maximum number of polls. Set to zero for no limit.
                          [default: 200]
  --help                  Show this message and exit.

New behavior:

planet data asset-wait --help    
Usage: planet data asset-wait [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Wait for an asset to be activated.

  Returns when the asset status has reached "activated" and the asset is
  available.

Options:
  --delay INTEGER         Time (in seconds) between polls.
  --max-attempts INTEGER  Maximum number of polls. Set to zero for no limit.
                          [default: 200]
  --help                  Show this message and exit.

  Valid entries for ITEM_TYPES: REScene|Sentinel2L1C|REOrthoTile|MOD09GQ|Senti
  nel1|PSScene|PSOrthoTile|MYD09GQ|Landsat8L1G|MYD09GA|SkySatCollect|SkySatSce
  ne|MOD09GA

Old behavior:

planet data asset-download psscene 20220101_153358_18_2421 basic_analytic_4b
Error: {"general": [{"message": "The requested item type does not exist."}], "field": {}}

New behavior:

planet data asset-download psscene 20220101_153358_18_2421 basic_analytic_4b
/Users/kevin.lacaille/code/repos/planet/planet-client-python/20220101_153358_18_2421_1B_AnalyticMS.tif: 100%|██████████████████| 280k/280k [00:04<00:00, 67.0MB/s]

Old behavior:

planet data asset-download --help                                               
Usage: planet data asset-download [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Download an activated asset.

  This function will fail if the asset state is not activated. Consider
  calling `asset-wait` before this command to ensure the asset is activated.

  If --checksum is provided, the associated checksums given in the manifest
  are compared against the downloaded files to verify that they match.

  If --checksum is provided, files are already downloaded, and --overwrite is
  not specified, this will simply validate the checksums of the files against
  the manifest.

  Output: The full path of the downloaded file. If the quiet flag is not set,
  this also provides ANSI download status reporting.

Options:
  --directory DIRECTORY  Base directory for file download.
  --filename TEXT        Custom name to assign to downloaded file.
  --overwrite            Overwrite files if they already exist.
  --checksum             Verify that checksums match.
  --help                 Show this message and exit.

New behavior:

planet data asset-download --help                                               
Usage: planet data asset-download [OPTIONS] ITEM_TYPE ITEM_ID ASSET_TYPE

  Download an activated asset.

  This function will fail if the asset state is not activated. Consider
  calling `asset-wait` before this command to ensure the asset is activated.

  If --checksum is provided, the associated checksums given in the manifest
  are compared against the downloaded files to verify that they match.

  If --checksum is provided, files are already downloaded, and --overwrite is
  not specified, this will simply validate the checksums of the files against
  the manifest.

  Output: The full path of the downloaded file. If the quiet flag is not set,
  this also provides ANSI download status reporting.

Options:
  --directory DIRECTORY  Base directory for file download.
  --filename TEXT        Custom name to assign to downloaded file.
  --overwrite            Overwrite files if they already exist.
  --checksum             Verify that checksums match.
  --help                 Show this message and exit.

  Valid entries for ITEM_TYPES: MYD09GA|PSOrthoTile|SkySatScene|MYD09GQ|Landsa
  t8L1G|SkySatCollect|REOrthoTile|Sentinel1|MOD09GA|Sentinel2L1C|PSScene|RESce
  ne|MOD09GQ

PR Checklist:

  • [] This PR is as small and focused as possible
  • [] If this PR includes proposed changes for inclusion in the changelog, the title of this PR summarizes those changes and is ready for inclusion in the Changelog.
  • [] I have updated docstrings for function changes and docs in the 'docs' folder for user interface / behavior changes
  • [] This PR does not break any examples or I have updated them

(Optional) @mentions for Notifications:
@sgillies

@kevinlacaille kevinlacaille added bug CLI/SDK Interface Update the CLI and SDK to the finalized interface data api subscriptions api labels Mar 31, 2023
@kevinlacaille kevinlacaille self-assigned this Mar 31, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@kevinlacaille
Copy link
Contributor Author

kevinlacaille commented Mar 31, 2023

TO DO:

  • Add test for new functions in planet.specs
    • Get rid of sill .sort() for test_get_supported_assets_success()
  • get rid of silly indexing of first item in asset_type in subscription_request asset_types = specs.validate_asset_type(item_types, asset_types[0])
  • Try and translate the planet.specs.SpecificationException error in catalog-request from click to get rid of long traceback. Adding @translate_exceptions doesn't seem to do anything 🤔

Sorry, something went wrong.

@kevinlacaille kevinlacaille marked this pull request as ready for review April 3, 2023 20:22
@kevinlacaille kevinlacaille changed the title Item type case insensitive orders subs 903 Item type and asset type validation in Data and Subscriptions Apr 4, 2023
@@ -503,9 +503,9 @@ async def search_update(ctx,
"""
async with data_client(ctx) as cl:
items = await cl.update_search(search_id,
name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undoing this so that it can be fixed by #908. CC @jreiberkyle

Copy link
Contributor

@jreiberkyle jreiberkyle left a comment

Choose a reason for hiding this comment

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

looking much better, still some fixes recommended. great work!

@@ -127,6 +127,13 @@ def catalog_source(
planet.exceptions.ClientError: If start_time or end_time are not valid
datetimes
'''
for i in range(len(item_types)):
Copy link
Contributor

Choose a reason for hiding this comment

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

This code errors out when I use multiple item-types:

planet-client-python$> planet subscriptions request-catalog --item-types REScene,PSScene --asset-types basic_analytic_b2 --geometry geometry.geojson --start-time 2022-02-02
Traceback (most recent call last):
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/bin/planet", line 11, in <module>
    load_entry_point('planet', 'console_scripts', 'planet')()
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 1059, in main
    rv = self.invoke(ctx)
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 1665, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 1665, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 1401, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/jennifer.kyle/.pyenv/versions/planet-client-python-3.7.9/lib/python3.7/site-packages/click/core.py", line 767, in invoke
    return __callback(*args, **kwargs)
  File "/Users/jennifer.kyle/pl/planet-client-python/planet/cli/cmds.py", line 57, in wrapper
    func(*args, **kwargs)
  File "/Users/jennifer.kyle/pl/planet-client-python/planet/cli/subscriptions.py", line 270, in request_catalog
    filter=filter)
  File "/Users/jennifer.kyle/pl/planet-client-python/planet/subscription_request.py", line 133, in catalog_source
    asset_types[i])
IndexError: list index out of range

it is fine if there is just one item-type

planet-client-python$> planet subscriptions request-catalog --item-types REScene --asset-types basic_analytic_b2 --geometry geometry.geojson --start-time 2022-02-02
{"type": "catalog", "parameters": {"item_types": ["REScene"], "asset_types": ["basic_analytic_b2"], "geometry": {"type": "Polygon", "coordinates": [[[-58.708965, -11.6562], [-58.66734, -11.6562], [-58.66734, -11.626594], [-58.708965, -11.626594], [-58.708965, -11.6562]]]}, "start_time": "2022-02-02T00:00:00Z"}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes I wrote this so you'd have to explicitly write out the asset type you wanted for a given item type. Sure, your example would be fine, but what if you want item_type_1, item_type_2, item_type_3, where item_type_1 and item_type_2 are both compatible with asset_type_a and item_type_3 is only compatible with asset_type_b. Would you want it to be able to parse something like

planet subscriptions request-catalog \
        --item-types item_type1,item_type_2,item_type_3 \    
        --asset-types asset_type_a, asset_type_b \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see your comment in Slack. As you pointed out, the docs claim that a subscription will only be successfully made if one item_type is provided. So, as I mention and show in my comment below, I've raised a ClientError if multiple item_types are provided.

@kevinlacaille
Copy link
Contributor Author

Now, we can validate multiple asset_types for a given item_type

planet subscriptions request-catalog \                                                            
        --item-types psscene \
        --asset-types ortho_analytic_4b,basic_analytic_8b_xml \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01

{"type": "catalog", "parameters": {"item_types": ["psscene"], "asset_types": ["ortho_analytic_4b", "basic_analytic_8b_xml"], "geometry": {"type": "Polygon", "coordinates": [[[7.05322265625, 46.81509864599243], [7.580566406250001, 46.81509864599243], [7.580566406250001, 47.17477833929903], [7.05322265625, 47.17477833929903], [7.05322265625, 46.81509864599243]]]}, "start_time": "2022-01-01T00:00:00Z"}}

As you pointed out in the docs (https://developers.planet.com/docs/subscriptions/source/#validation). So, now the SDK will fail gracefully if more than one item_type is provided:

planet subscriptions request-catalog \
        --item-types psscene,psscene \
        --asset-types ortho_analytic_4b,basic_analytic_8b_xml \
        --geometry ../jsons_for_tests/aoi.geojson \
        --start-time 2022-01-01
Error: Subscription can only be successfully created if one item type is specified.

I'd love to change item_types to item_type, but item_types is used in the docs, so I'm not sure where we stand on this.

@jreiberkyle
Copy link
Contributor

I'd love to change item_types to item_type, but item_types is used in the docs, so I'm not sure where we stand on this.

generally I agree that the term item-types is inaccurate here, but keeping it the same as the subscriptions api and the docs is going to be the best play for now :sadpanda:

Copy link
Contributor

@jreiberkyle jreiberkyle left a comment

Choose a reason for hiding this comment

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

getting picky with tests on this one. code looks great. I'll approve here and you can merge when you make the test changes, if you agree to them.

@jreiberkyle
Copy link
Contributor

looks great! Great job!

@jreiberkyle jreiberkyle merged commit e3bda2f into main Apr 7, 2023
@jreiberkyle jreiberkyle deleted the item-type-case-insensitive-orders-subs-903 branch April 7, 2023 20:15
@jreiberkyle jreiberkyle mentioned this pull request Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CLI/SDK Interface Update the CLI and SDK to the finalized interface data api subscriptions api
Projects
None yet
2 participants