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

Added as_pure_dictionary method #25

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Conversation

ilbuonmarcio
Copy link

I recently had a problem with pickling and unpickling UltraDict instances with recurse=True.
After some wild bug hunting I realized that accessing UltraDict's data attribute/property didn't convert nested UltraDict items also to basic dictionaries, thus breaking pickling and unpickling actions, other than stopping following updates from syncing.

I added the method as_pure_dictionary, with proper unit tests, and tested them in production with one single shared memory between 6 high frequency realtime processes both using reads and writes in different parts of the same UltraDict with recurse=True enabled, with success!

Basic usage for me in that project was something like this pseudocode:

ultra = UltraDict(
    {
        "1": "hello",
        "2": 5,
        "3": {
            "1": 1,
            "2": {
                "1": True,
                "2": None,
                "3": [1, 2, 3]
            },
            "3": [4, 5, 6, {"7": 8}]
        }
    },
    recurse=True,
    create=True
)

as_dict = ultra.as_pure_dictionary()
db.save(pickle.dumps(as_dict))
# Saving it to database

# Some time later, on the next app opening
as_dict = pickle.loads(db.load())
ultra = UltraDict(as_dict, recurse=True, create=True)

# And start reusing it as I left it!
ultra["2"] = 18

Hope it sounds good for you, and hope it helps somebody as well as it helped me!

If you have questions let me know, I'm happy to fix things if they aren't properly good enough :)

@ronny-rentner
Copy link
Owner

Thanks for your pull request. I expect to merge this on the weekend.

@ilbuonmarcio
Copy link
Author

Hi, any problems regarding this pull request? Should I fix something?

@ronny-rentner
Copy link
Owner

Hey, sorry, no problem at all. I wanted to merge but then there were issues with my build pipeline as I added some performance tests (to detect performance regressions) which are not working yet and never had the time to finish it. I'll try to do it asap. Sorry again and thanks for your contribution. Much appreciated.

@ilbuonmarcio
Copy link
Author

If you need help for contributions I'm here to help if needed :)

@ronny-rentner ronny-rentner merged commit 0dec0b0 into ronny-rentner:dev Sep 17, 2024
0 of 39 checks passed
@ronny-rentner
Copy link
Owner

So it's finally merged, thanks for your patience. UltraDict v0.0.7 is coming soon.

@ilbuonmarcio
Copy link
Author

Nice! Thanks for your support :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants