-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Versification dictionary fills up with custom versifications and causes exception to be thrown #1367
Comments
Anyone can create a PR! (Not everyone can get past the review...) |
I am a little curious as to why you're needing to create a bunch of custom versifications. Usually, those are pretty rare. But your use case already sounds a little different. |
OK! I look forward to it haha
It's possible that some of these are the result of test projects - not sure. In any case, we'd like Machine to be robust in these circumstances. What's the rationale for storing the versifications in the static dictionary in the first place? Caching? |
I'm not 100% sure, but I believe the static caching has two purposes: performance and also to ensure referential equality. I think we want to ensure that each distinct versification is only loaded once so we do not have to deep-compare two identical versifications. @FoolRunning could probably shed more light on that and correct me if I'm wrong. |
Yes, it is for caching. The ScrVers is the wrapper for the versification with the internal mappings being done through the Versification class (The Versification class should never be referenced directly in an application). The ScrVers class is serializable so it can be deserialized from an XML file. What we didn't want is for each created instance of ScrVers to create a new copy of the versification tables (which would be very wasteful). This is the reason that all versifications are cached until the program is exited (i.e. in a static variable). Getting a "duplicate key" exception suggests that the versification table is not be used correctly (Not your fault - there isn't any documentation 😅). You shouldn't ever load the same versification table more than once. If a versification is customized, it should have a unique name (usually the ID of the scripture project). As for having it fill up, that is usually not a problem for most applications. I'm not sure what your application does, but if you're filling up with thousands of custom versifications, then one option would be to create a PR with a new method on Versification.Table that can remove a cached versification - but the application would have to be very sure that there are no ScrVers instances floating around referencing a removed Versification instance. EDIT: Forgot to mention that you should, ideally, not be calling Versification.Table.Load at all - you should just be creating ScrVers implementations (giving it a name or type) and let that handle the loading. |
For reference, here is simplified version of Paratext's implementation of the versification table (set via Versification.Table.Implementation) that handles custom versifications from projects (The name contains a "-" followed by the ID of the project):
Hopefully that clears up some things. EDIT: If you're using ParatextData in your application, this implementation is there, it just needs to be set: |
This is very helpful - thank you! Just now seeing your edits. Sounds like, yes, maybe there's a bug on our end since it sure seems like this is an issue that shouldn't be happening. Here's the relevant snippet of code on our end that's calling the
Does something stand out to you about this as incorrect, @FoolRunning? |
@Enkidu93, Yeah, this is what I was trying to say. You shouldn't be loading the versifications like that. You should just always be doing |
OK, I think I'm understanding now. So we'll need to create a custom |
@ddaspit, see here. |
@Enkidu93, Sorry for the slow response. |
We're encountering this issue in Machine in the Machine/Serval/ScriptureForge pipeline. See here.
A quick fix could be as simple as changing the
Add
in this line to aTryAdd
. But given that we really don't need theLoad
method to save versifications to an internal dictionary for our use-case, a better solution might be to just have aLoad
function that does not add anything to the dictionary.(I'm happy to code up a solution and put in a PR myself if I have the go-ahead).
The text was updated successfully, but these errors were encountered: