GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change MerginProject constructor to force one instance per project by dvdkon · Pull Request #283 · MerginMaps/python-api-client

Conversation

@dvdkon

@dvdkon dvdkon commented Dec 17, 2025

Copy link
Copy Markdown

Currently there can be multiple instances of MerginProject in memory that represent a single project (directory). This is an issue, because doing an operation on one instance will desync metadata in the others, which caused syncing to fail in db-sync.

This PR changes the MerginProject constructor to return the existing instance for a given directory, if one exists. It also bumps the library version, so I can make subsequent changes in db-sync.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dvdkon dvdkon mentioned this pull request Dec 17, 2025
Stop caching MerginProjects, since that's now done by the client library MerginMaps/db-sync#169
Draft
wonder-sk
wonder-sk reviewed Dec 18, 2025
View reviewed changes
Comment thread mergin/merginproject.py Outdated
# directory paths to instances.
# The dictionary is a WeakValueDictionary so we don't cause memory leaks
# (when the instance is GC'd, the entry is deleted).
project_cache: weakref.WeakValueDictionary[str, "MerginProject"] = {}

@wonder-sk wonder-sk Dec 18, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand... the type annotation is WeakValueDictionary - but doesn't project_cache become a normal dict if set it to {} ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dvdkon dvdkon Dec 18, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's just me being an idiot, sorry. Though I wonder why my IDE didn't complain...

I've force-pushed a fix, since it's just one line.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dvdkon
Change MerginProject constructor to force one instance per project
9ab77de
@dvdkon
dvdkon force-pushed the project-single-instance branch from 0596d56 to 9ab77de Compare December 18, 2025 16:38
MarcelGeo
MarcelGeo reviewed Dec 18, 2025
View reviewed changes

@MarcelGeo MarcelGeo left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dvdkon , could you run tests with your version of code? You probably do not need to fork repo, instead of this -> use clone.

This is good idea to do it in this way. I'm wondering if this is not like 🩹 for buggy behavior in db-sync itself. In plugin are flying the MerginProject instances and no issues with that. Yeah, we could probably solve initialisation of Geodiff. @wonder-sk

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread mergin/merginproject.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread mergin/merginproject.py Outdated
return instance

instance = super().__new__(cls)
cls.project_cache[directory] = instance

@MarcelGeo MarcelGeo Dec 18, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to pass project_cache to class directly?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dvdkon dvdkon Dec 19, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's already there since it's defined as a class property. cls.project_cache here is equivalent to MerginProject.project_cache.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread mergin/merginproject.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread setup.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@dvdkon
Apply changes from review
f4a3cf6
@dvdkon

dvdkon commented Dec 19, 2025

Copy link
Copy Markdown
Author

could you run tests with your version of code?

Sadly I don't have the right (non-trial) account to run tests on the dev instance.

I'm wondering if this is not like 🩹 for buggy behavior in db-sync itself. In plugin are flying the MerginProject instances and no issues with that.

We could probably work around the desync issues by just being careful in db-sync, but I think since it doesn't make sense to have multiple instances for one project, it's better to just ensure that it doesn't happen. It also makes sure no more bugs like this will appear in the future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MarcelGeo
MarcelGeo marked this pull request as draft January 12, 2026 14:53
@wonder-sk

wonder-sk commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

On hold (see MerginMaps/db-sync#170)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@wonder-sk wonder-sk wonder-sk left review comments
@MarcelGeo MarcelGeo MarcelGeo left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@dvdkon @wonder-sk @MarcelGeo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.