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

Don't error on a PDFv2 with multiple entities if it's not required #1606

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,21 @@ def find_entity(

entity: Optional[T] = None

# Determine the package entity to convert, there must be one
if entity_id:
# If the user specified a package entity ID (or we inferred one from the app entity), use that one directly
# If we're looking for a specific entity, use that one directly
entity = entities.get(entity_id)
elif len(entities) == 1:
# Otherwise, if there is only one package entity, fall back to that one
# Otherwise, if there is only one entity, fall back to that one
entity = next(iter(entities.values()))
elif len(entities) > 1:
# If there are multiple package entities, the user must specify which one to use
elif len(entities) > 1 and required:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the change, everything else is just cleaning up comments

# If there are multiple entities and it's required,
# the user must specify which one to use
raise ClickException(
f"More than one {entity_type} entity exists in the project definition file, "
f"specify {disambiguation_option} to choose which one to operate on."
)

# If we don't have a package entity to convert, error out since it's not optional
# If we don't have a package entity to convert, error out if it's required
if not entity and required:
with_id = f'with ID "{entity_id}" ' if entity_id else ""
raise ClickException(
Expand Down
18 changes: 18 additions & 0 deletions tests/nativeapp/test_v2_to_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ def test_v2_to_v1_conversions(pdfv2_input, expected_pdfv1, expected_error):
"More than one application entity exists in the project definition file, "
"specify --app-entity-id to choose which one to operate on.",
],
[
{
"definition_version": "2",
"entities": {
**package_v2("pkg1"),
**app_v2("app1", "pkg1"),
**app_v2("app2", "pkg1"),
},
},
"",
"",
False,
{
"definition_version": "1.1",
"native_app": native_app_v1("pkg1", "pkg1", ""),
},
None,
],
[
{
"definition_version": "2",
Expand Down
Loading