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.

Field name cannot be a number

See original GitHub issue

I am trying to set a Field’s name prop as a number (e.g. <Field name="123" component="input" />).

The problem is that when the fields key in state is created, instead of creating an object with the key “123”, it creates an array with a length of 124, filled with nulls except the last index.

The issue I believe is that the setIn function, which is what creates the state, does not differentiate between dot and bracket syntax. If it sees a number, it creates an array. So even though it is being called as setIn(result, 'fields.123.visited', true), it is being considered as setIn(result, 'fields[123].visited', true).

The solution would probably be to have this function account for whether or not dot notation was used when encountering a number. The other solution would be to just not use numbers as names, but I feel that since this is valid in the DOM, it should be able to be done here as well.

I already wrote a failing test, but don’t have a working solution yet.

I’m curious to know if I am understanding the problem correctly, and if this functionality is something that should be supported.

Thanks

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
erikrascommented, Jan 6, 2017

I just spent an hour investigating this.

In v5, I had quite a bit of code that was parsing the dot-vs-bracket notation, and it was a veritable mess, and a source of very many bugs. It was a very conscious decision to switch to use _.toPath() in v6 to avoid that headache.

So I think the answer is that numeric field names are not supported. Prefix it with something. e.g. 'field_123'.

If you wrote a very thoroughly tested implementation of setIn, for both plain and immutable structures, I might consider a change of this policy.

0reactions
lock[bot]commented, Jun 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

000310: The Field name must not start with a number.
A field name starting with a number is not supported and cannot be added to the table or feature class. Solution. Do not...
Read more >
SQL Error - "Field name cannot be blank"
The most recent error we keep getting is "Field Name cannot be blank". We have tried ensuring the attributes in the DE that...
Read more >
ERROR: "The first character in this name cannot be a number
This issue occurs when the name of the file is provided as a number in the beginning of the file name. Example. 1.txt;...
Read more >
How to Troubleshoot and Fix Excel Pivot Table Errors
The pivot table error, "field name is not valid", usually appears because one or more of the heading cells in the source data...
Read more >
Spring Data REST - JsonGenerationException: Can not write ...
HttpMessageNotWritableException: Could not write content: Can not write a number, expecting field name; nested exception is ...
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