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

[bug] Error for failing to decode JSON should include the JSON #126

Closed
amnn opened this issue Jun 30, 2023 · 4 comments
Closed

[bug] Error for failing to decode JSON should include the JSON #126

amnn opened this issue Jun 30, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@amnn
Copy link

amnn commented Jun 30, 2023

Below is a stacktrace from executing a transaction where the fullnode being used returned an unexpected response. The error shows that pysui's types expected a reference field but one could not be found. In these cases, it would also be useful to know what the JSON that was being serialized looked like, to figure out why the fullnode produced that response.

Example

  File "$SITE/ddxt/deepbook_async.py", line 303, in async_execute_tx
    return tx.execute(gas_budget=gas_budget)
  File "$SITE/pysui/sui/sui_clients/transaction.py", line 1451, in execute
    tx_b64 = base64.b64encode(self._build_for_execute(gas_budget).serialize()).decode()
  File "$SITE/pysui/sui/sui_clients/transaction.py", line 1398, in _build_for_execute
    result = self.client.execute(InspectTransaction(sender_address=for_sender, tx_bytes=tx_kind_b64))
  File "$SITE/pysui/sui/sui_clients/sync_client.py", line 98, in execute
    return SuiRpcResult(True, None, builder.handle_return(result.result_data["result"]))
  File "$SITE/pysui/sui/sui_builders/base_builder.py", line 157, in handle_return
    return getattr(self._handler_cls, self._handler_func)(indata)
  File "$SITE/pysui/sui/sui_txresults/complex_tx.py", line 330, in factory
    return cls.from_dict(in_data)
  File "$SITE/dataclasses_json/api.py", line 72, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
  File "$SITE/dataclasses_json/core.py", line 197, in _decode_dataclass
    value = _decode_dataclass(field_type, field_value,
  File "$SITE/dataclasses_json/core.py", line 201, in _decode_dataclass
    init_kwargs[field.name] = _decode_generic(field_type,
  File "$SITE/dataclasses_json/core.py", line 275, in _decode_generic
    res = _decode_generic(type_arg, value, infer_missing)
  File "$SITE/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "$SITE/dataclasses_json/core.py", line 317, in <genexpr>
    items = (_decode_dataclass(type_arg, x, infer_missing)
  File "$SITE/dataclasses_json/core.py", line 159, in _decode_dataclass
    field_value = kvs[field.name]
KeyError: 'reference'
@FrankC01
Copy link
Owner

I will be adding a dump pre-JSON deserialization to data-classes this weekend although have a bit more context like the kind of commands being built with SuiTransaction (async or sync). Is it just a move_call? If so, what is the target?

@amnn
Copy link
Author

amnn commented Jun 30, 2023

I'm not sure how easy the specific issue in the example is to reproduce, but @nathan-kairon, would you mind sharing some extra context here?

My understanding is that it's a fullnode that's just acting up and producing the wrong data for a devInspect call, and we'd like to see what response it did produce to figure out why.

@FrankC01
Copy link
Owner

FrankC01 commented Jul 1, 2023

Basically the above exception is saying one of the information fields returns in the Effects portion of the Inspect results is malformed. The 'reference' is a property of an OwnedObjectRef versus a more generic ObjectRef

In pysui the mapping of an Effect has the following (edited specifically to use of the above and type renamed for easy association to JSON schema:

    gas_object: OwnedObjectRef = field(metadata=config(letter_case=LetterCase.CAMEL))
    mutated: Optional[list[OwnedObjectRef]] = field(default_factory=list)
    created: Optional[list[OwnedObjectRef]] = field(default_factory=list)
    deleted: Optional[list[ObjectRef]] = field(default_factory=list)
    wrapped: Optional[list[ObjectRef]] = field(default_factory=list)
    unwrapped: Optional[list[OwnedObjectRef]] = field(default_factory=list)
    unwrapped_then_deleted: Optional[list[ObjectRef]] = field(
        metadata=config(letter_case=LetterCase.CAMEL), default_factory=list
    )
    shared_objects: Optional[list[GenericRef]] = field(
        metadata=config(letter_case=LetterCase.CAMEL), default_factory=list
    )

I did find, and corrected, that unwrapped_then_deleted (in pysui) was declared as a OwnedObjectRef but I changed this as well to align with the spec as it is an ObjectRef)

Also, the latest push to branch p0280 includes performing a modified inspection wrapped in try/except
In the event of a KeyError I move it to a ValueError so:

try:
   tx.execute(...)
except ValueError a ve:
   print(ve)

May provide insight.

@FrankC01 FrankC01 self-assigned this Jul 2, 2023
@FrankC01 FrankC01 added the bug Something isn't working label Jul 2, 2023
@FrankC01 FrankC01 added this to pysui Jul 2, 2023
@github-project-automation github-project-automation bot moved this to Backlog in pysui Jul 2, 2023
@FrankC01 FrankC01 moved this from Backlog to In Progress in pysui Jul 2, 2023
@FrankC01 FrankC01 changed the title Error for failing to decode JSON should include the JSON [bug] Error for failing to decode JSON should include the JSON Jul 2, 2023
@FrankC01
Copy link
Owner

FrankC01 commented Jul 5, 2023

Added to 0.28.0

@FrankC01 FrankC01 closed this as completed Jul 5, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in pysui Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

2 participants