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.

Saving dictionaries can unintentionally generate invalid data files

See original GitHub issue
void Test()
{
    var dicc = new Dictionary<int, Vector3>()
    {
        [22] = new Vector3(-12, 323, 432.43f),
        [55] = new Vector3(-1, 0, 100),
        [-100] = new Vector3(Mathf.PI, Mathf.PI, Mathf.PI),
    };

    var file = new DataFile("test", autoSave: true);
    file.Set("dicc boi", dicc);
}

That code generates this file:

dicc boi:
    22:
        x: -12
        y: 323
        z: 432.43
    55:
        x: -1
        y: 0
        z: 100
    -100:
        x: 3.141593
        y: 3.141593
        z: 3.141593

Notice the key called “-100”. Keys are not allowed to begin with -, as that character is reserved for list nodes. Trying to read the file later will throw errors. This can also happen when using DataFile.SaveAsDictionary().

The solution is probably to allow - in key nodes, and determine what is a list node by the absence of :.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
JimmyCushniecommented, Jan 17, 2019

Fixed in 2487cce and will be in the next release. Dictionaries, when serialized with their keys as children, will always surround the keys in quotes.

0reactions
JimmyCushniecommented, Jan 18, 2019

In 4934481 I fixed this in a much nicer way. Dictionaries now check if their key is a valid SUCC key, and if not, they serialize as an array of KeyValuePair.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to store a dictionary as a separate file, and read ...
Is there a way to do this. I tried to make a text file "gene_data1.txt" that just included the dictionary. So, the contents...
Read more >
Create a Dictionary in Python – Python Dict Methods
In this article, you will learn the basics of dictionaries in Python. You will learn how to create dictionaries, access the elements inside ......
Read more >
Save a dictionary to a file
A dictionary in Python is a collection where every value is mapped to a key. They are unordered, mutable and there is no...
Read more >
Python Save Dictionary To File [4 Ways]
Learn to save a dictionary to a file in Python. Write dict objects to text, csv, and binary files using the pickle, json,...
Read more >
How to use sessions
The session data will be stored using Django's tools for cryptographic signing ... The same invalidation happens if the client storing the cookie...
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