question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] The CairoSerializer cannot handle names starting with a underscore

See original GitHub issue

I’ve a Cairo contract using names starting with a underscore. And using the FunctionCallSerializer for get back data from Cairo to Python (to decode transactions return data) will raise:

ValueError: Field names cannot start with an underscore: '_name`

It’s a namedtuple limitation, from here: https://github.com/software-mansion/starknet.py/blob/36acd9f75e189b94a75ac413f99e72984d1e3121/starknet_py/utils/data_transformer/data_transformer.py#L207-L209

Python version

All.

Expected Behavior

Names starting with a underscore should not be a problem.

Current Behavior

ValueError: Field names cannot start with an underscore: '_name`

Possible Solution

  1. We could use the rename kwargs from the namedtuple, but will would loose the real name then.
  2. An idea using dataclasses, but we would then loose the tuple comparison (which is mandatory to keep):
 from dataclasses import make_dataclass

 # instead of the namedtuple:
 result = make_dataclass("Result", [(k, v) for k, v in ...], order=True, frozen=True, slots=True)
  1. 💟 https://github.com/ksamuel/drecord

Steps to Reproduce

  1. Use a name starting with a underscore, in any Cairo method.
  2. Use FunctionCallSerializer.to_python().
  3. See the exception.

Context (Environment)

The issue is quite big, because we’re using the FunctionCallSerializer in the Ape StarkNet plugin to decode transactions return data. The goal is to leverage all the fantastic work you’ve already done to decode all kind of data types (like arrays, and custom complex structs).

Detailed Description

Possible Implementation

I like the 3rd idea. If you think it’s something you would like to implement, I could give a try.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ca11ab1ecommented, Jul 22, 2022

Oh OK 😃 I know that FunctionCallSerializer calls CairoSerializer under the wood, and as FunctionCallSerializer is the new DataTransformer name, I used it. But yes, both have the same issue at the end.

1reaction
Arcticaecommented, Jul 21, 2022

Or me if he’s too busy 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Machine Name Can't Have Underscores [#3179779] - Drupal
So I can have underscores according to the error, but it won't save unless the machine-name is free of underscores. The UI is...
Read more >
[SERVER-445] Can't reference collection names beginning ...
If your collection name includes special characters, such as the underscore character, or begins with numbers, then to access the collection use ...
Read more >
wrong location for heimdal-1.5.3.tar.gz and xfce4-quicklauncher ...
However, please note that the upper bound cannot always be respected, e.g., ... to set the name of the user who last modified...
Read more >
NEWS for R version 4.2.2 Patched (2022-12-14 r83470)
On Windows the untar() function now quotes the directory name when using an external tar utility, so R CMD check will handle pathnames...
Read more >
Ability to search when underscore exists in task name
When I do a search for vsa2424 is doesn't find the task. Only if I take out the underscore from the task name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found