Skip to content

Conversation

@VipulMascarenhas
Copy link
Member

@VipulMascarenhas VipulMascarenhas commented Apr 18, 2024

Description

There's a bug in python fire that causes the __str__ implementation of the dataclass to be ignored in case the result is a list of dataclasses. If the result is just one instance of dataclass and not a list, then __str__ implementation works fine.

We can use a custom serializer to make sure that the output is correctly updated.

Tests

  1. Output of ads aqua model list with indent=4 in __str__, but NOT using serialize parameter for fire.Fire(). There are spaces in the output, but fire prints it in one line.
{     "compartment_id": "ocid1.compartment.oc1..<ocid>",     "icon": "",     "id": "ocid1.datasciencemodel.oc1.iad.<ocid>",     "is_fine_tuned_model": false,     "license": "license name",     "name": "model name",     "organization": "organization",     "project_id": "",     "tags": {         "license": "license name",         "task": "task name",         "OCI_AQUA": "active",         "organization": "organization",         "ready_to_fine_tune": "false"     },     "task": "task name",     "time_created": "2024-03-25T06:40:22.719000+00:00",     "console_link": [         "https://cloud.oracle.com/data-science/models/ocid1.datasciencemodel.oc1.iad.<ocid>?region=<region-name>"     ],     "search_text": "some_search_text",     "ready_to_deploy": true,     "ready_to_finetune": false }
...
...
  1. Output of ads aqua model list with indent=4 in __str__, with serialize parameter for fire.Fire(). This will be the new output after the code changes in this PR.
{
    "compartment_id": "ocid1.compartment.oc1..<ocid>",
    "icon": "",
    "id": "ocid1.datasciencemodel.oc1.iad.<ocid>",
    "is_fine_tuned_model": false,
    "license": "license name",
    "name": "model name",
    "organization": "organization",
    "project_id": "",
    "tags": {
        "license": "license name",
        "task": "task name",
        "OCI_AQUA": "active",
        "organization": "organization",
        "ready_to_fine_tune": "false"
    },
    "task": "task name",
    "time_created": "2024-03-25T06:40:22.719000+00:00",
    "console_link": [
        "https://cloud.oracle.com/data-science/models/ocid1.datasciencemodel.oc1.iad.<ocid>?region=<region-name>"
    ],
    "search_text": "some_search_text",
    "ready_to_deploy": true,
    "ready_to_finetune": false
}
...
...
  1. Output of ads aqua model list without __str__ function (this was commented out in serializer.py ) but using serialize parameter for fire.Fire(). This will not be used, but added here to show the output of serialize function.
compartment_id: ocid1.compartment.oc1..<ocid>
console_link:
- https://cloud.oracle.com/data-science/models/ocid1.datasciencemodel.oc1.iad.<ocid>?region=<region-name>
icon: ''
id: ocid1.datasciencemodel.oc1.iad.<ocid>
is_fine_tuned_model: false
license: license name
name: model name
organization: organization
project_id: ''
ready_to_deploy: true
ready_to_finetune: false
search_text: some_search_text
tags:
  OCI_AQUA: active
  license: license name
  organization: organization
  ready_to_fine_tune: 'false'
  task: task name
task: task name
time_created: 2024-03-25 06:40:22.719000+00:00

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 18, 2024
@mingkang111
Copy link
Member

mingkang111 commented Apr 19, 2024

Can you please rebase the feature/aquav1.0.1 ? The feature/aquav1.0.1 just rebase main.

Prints:
The string representation of each dataclass object.
"""
if isinstance(data, list):
Copy link
Member Author

@VipulMascarenhas VipulMascarenhas Apr 19, 2024

Choose a reason for hiding this comment

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

@mayoor removed redundant __str__ check, just printing the object is enough.

@VipulMascarenhas VipulMascarenhas merged commit fa04a82 into feature/aquav1.0.1 Apr 22, 2024
@VipulMascarenhas VipulMascarenhas deleted the ODSC-55947/pretty_print_fire_output branch April 22, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants