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

Make Sense.PartOfSpeech an object instead of a string #1350

Merged
merged 31 commits into from
Jan 15, 2025

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Jan 7, 2025

Fixes #1232.

Backend and frontend changes appear to be working; here's the frontend viewer showing the Sena-3 test data:

image

And here's the sense display, showing that all the parts of speech are being looked up properly:

image

There's almost certainly more work to be done, but this seems to be a good start.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 7, 2025

Also getting some errors in FwLiteProjectSync.Tests.SyncTests.PartsOfSpeechSyncInEntries such as "One or more errors occurred. (The instance of entity type 'PartOfSpeech' cannot be tracked because another instance with the key value '{Id: a8e41fd3-e343-4c7c-aa05-01ea3dd5cfb5}' is already being tracked."

Don't have time to track those down right now, but recording the errors here so that I remember to track them down later.

Copy link

github-actions bot commented Jan 7, 2025

C# Unit Tests

104 tests   104 ✅  5s ⏱️
 16 suites    0 💤
  1 files      0 ❌

Results for commit 1e14f4c.

♻️ This comment has been updated with latest results.

@rmunn rmunn mentioned this pull request Jan 7, 2025
@rmunn
Copy link
Contributor Author

rmunn commented Jan 7, 2025

One place this is happening is in BulkCreateEntries during ImportProject: if more than one sense had the same part of speech (very likely), then the code is currently trying to create those as separate DB entries rather than as references to the same one. I need to change how the DB handles PartOfSpeech to be a relation (looked up by PartOfSpeechId) here.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 8, 2025

@hahn-kev - I've gotten most of this working, but I could use some help with some of the remaining test failures. I know there's code somewhere that's creating duplicate parts of speech in the database instead of simply making references, but I'm not sure exactly where it is. There's about one level of abstraction more than I'm managing to fit in my head right now, and I suspect that extra level of abstraction is where I would need to look to fix this issue.

Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

this looks like a good start, this still some things to do. I've fixed a few things by changing the CreateSenseChange to only use the PartOfSpeech Id, and I've fixed some tests which were failing by always querying out the PartOfSpeech object in the relevant places.

backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs Outdated Show resolved Hide resolved
backend/FwLite/MiniLcm.Tests/BasicApiTestsBase.cs Outdated Show resolved Hide resolved
backend/FwLite/MiniLcm/SyncHelpers/SenseSync.cs Outdated Show resolved Hide resolved
backend/LfClassicData/LfClassicMiniLcmApi.cs Outdated Show resolved Hide resolved
backend/LfClassicData/LfClassicMiniLcmApi.cs Outdated Show resolved Hide resolved
@rmunn
Copy link
Contributor Author

rmunn commented Jan 8, 2025

@hahn-kev - Addressed your review comments so far. I still plan to make one more change (see #1350 (comment) for details) tomorrow to make GetPartOfSpeech make a single query instead of two, but I'm otherwise done with your suggested changes so far and ready to start working on frontend code.

Copy link

github-actions bot commented Jan 8, 2025

UI unit Tests

12 tests   12 ✅  0s ⏱️
 4 suites   0 💤
 1 files     0 ❌

Results for commit 1e14f4c.

♻️ This comment has been updated with latest results.

@rmunn rmunn force-pushed the feat/crdt-part-of-speech-object-in-senses branch from dd04723 to dc31a2f Compare January 9, 2025 16:06
@rmunn
Copy link
Contributor Author

rmunn commented Jan 9, 2025

Rebased on top of current develop since some recent PRs were touching viewer-related code and I want to solve merge conflicts before they have a chance to happen.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 9, 2025

I now have the frontend working at first glance with the test Sena-3 project; screenshots in PR description above. I'm sure there are bugs that I'll reveal once I start trying to sync projects, but the Sena-3 test data has now been converted to use objects and all the parts of speech that Sena-3 references have been put into the data that entry-data.ts exports. Now I'll start actually using this with other test projects, to identify any further bugs. Then once I can't find any more obvious bugs, I'll mark the PR ready for review.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 9, 2025

@hahn-kev - How do I update DataModelSnapshotTests.VerifyDbModel.verified.txt so that the LcmCrdt.Tests.DataModelSnapshotTests.VerifyDbModel test will pass? My change to the type of Sense.PartOfSpeech is obviously what's causing this test failure here.

Besides that test, all backend tests passing except for one:

backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs(45): error TESTERROR:
FwLiteProjectSync.Tests.UpdateDiffTests.SenseDiffShouldUpdateAllFields (116ms): Error Message: Expected property before.PartOfSpeech to be MiniLcm.Models.PartOfSpeech
{
    DeletedAt = <2025-01-09 03:56:58.6540783 -5h>,
    Id = {0edb0965-c108-31ab-4804-e50a1a62acd6},
    Name = {[MiniLcm.Models.WritingSystemId
        {
            Code = "jbu"
        }] = "Music", [MiniLcm.Models.WritingSystemId
        {
            Code = "nxk"
        }] = "Unbranded", [MiniLcm.Models.WritingSystemId
        {
            Code = "oar"
        }] = "deposit"
    }
    ,
    Predefined = True
}, but found <null>.

I might need some help figuring that one out too; it's not clear to me why before.PartOfSpeech is ending up null here.

This is getting very close to being ready.

Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

Hum, I just realized an issue. Sense now has 2 properties which can specify the PartOfSpeech Id, either the PartOfSpeechId property or the PartOfSpeech object Id property. This means the API consumer could specify different Ids in each property, either when creating or updating the PoS. I believe our frontend only changes the PosId on the sense, not the object so when we send the Sense to be updated it also has this conflict. I think the most sensible thing would be to validate that the Ids match on both and if they don't then we throw a validation error. We could make an exception and say that if the PoS object is null and the PoSId on the sense is not then we use the value on the Sense, this would work best with our existing frontend as we would just need to set the object to null before we send it to the api. This won't represent a problem for FW Sync as both properties will always be the same.

@hahn-kev
Copy link
Collaborator

@hahn-kev - How do I update DataModelSnapshotTests.VerifyDbModel.verified.txt so that the LcmCrdt.Tests.DataModelSnapshotTests.VerifyDbModel test will pass? My change to the type of Sense.PartOfSpeech is obviously what's causing this test failure here.

Besides that test, all backend tests passing except for one:

backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs(45): error TESTERROR:
FwLiteProjectSync.Tests.UpdateDiffTests.SenseDiffShouldUpdateAllFields (116ms): Error Message: Expected property before.PartOfSpeech to be MiniLcm.Models.PartOfSpeech
{
    DeletedAt = <2025-01-09 03:56:58.6540783 -5h>,
    Id = {0edb0965-c108-31ab-4804-e50a1a62acd6},
    Name = {[MiniLcm.Models.WritingSystemId
        {
            Code = "jbu"
        }] = "Music", [MiniLcm.Models.WritingSystemId
        {
            Code = "nxk"
        }] = "Unbranded", [MiniLcm.Models.WritingSystemId
        {
            Code = "oar"
        }] = "deposit"
    }
    ,
    Predefined = True
}, but found <null>.

I might need some help figuring that one out too; it's not clear to me why before.PartOfSpeech is ending up null here.

This is getting very close to being ready.

For the verification test you copy/rename DataModelSnapshotTests.VerifyDbModel.received.txt to DataModelSnapshotTests.VerifyDbModel.verified.txt overwriting the existing one. You can read about verify here if you want.

As for the test, it's ending up null because we don't touch the PartOfSpeech property at all in the DiffUpdate. I wouldn't worry too much about it as that's a fair bit of code that needs to be cleaned up since we refactored our update code with the whole before after convention. You can just configure that test to ignore the PartOfSpeech property like similar to the other properties it's excluding.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 10, 2025

I think the most sensible thing would be to validate that the Ids match on both and if they don't then we throw a validation error.

Yep, now that #1344 is approved I'm planning to rebase this PR on top of the validation and then add some validation to make sure that PartOfSpeech.Id == PartOfSpeechId (and handle null / Guid.Empty sensibly). Glad to see we're on the same page as far as the design.

rmunn added 12 commits January 10, 2025 10:08
Auto-generated types for frontend have picked up the change of
Sense.PartOfSpeech from a string to an object, so now it's time
to change the frontend code accordingly.
More UI changes will ripple out from here
Having the complete list ensures that the Sena-3 test project's grammar
picker, and the display of the parts of speech, will work.
Unit tests expects a specific exception type, so we must be consistent
The SenseDiffToUpdate method specifically excludes the PartOfSpeech
object now, so the test shouldn't expect PartOfSpeech updated.
@rmunn rmunn force-pushed the feat/crdt-part-of-speech-object-in-senses branch from dd0c5a9 to 93bc1b5 Compare January 10, 2025 16:13
@rmunn rmunn force-pushed the feat/crdt-part-of-speech-object-in-senses branch from 00335e4 to 4890857 Compare January 10, 2025 18:23
@rmunn rmunn self-assigned this Jan 10, 2025
@hahn-kev
Copy link
Collaborator

@rmunn I've pushed a fix for the test that was failing (the sync tests operate on the same data, so one test failure can effect others). The test in question was using a part of speech before it was created which was causing the problem. I also fixed some issues in the CreateSenseChange as it would add references to Parts of speech and Semantic domains even if they were deleted, that's fixed now too.

@rmunn
Copy link
Contributor Author

rmunn commented Jan 14, 2025

@hahn-kev - Thanks to your fixes, this seems to be working now: all tests are passing, both in GHA and locally on my machine, and I've addressed all the review comments you left earlier. Any other changes needed before this is ready to merge?

@rmunn rmunn requested a review from hahn-kev January 14, 2025 17:16
@rmunn rmunn marked this pull request as ready for review January 14, 2025 23:08
Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

looks good, take a look at the one change I did to avoid a concurrency issue

@rmunn rmunn merged commit bb51178 into develop Jan 15, 2025
24 checks passed
@rmunn rmunn deleted the feat/crdt-part-of-speech-object-in-senses branch January 15, 2025 15:22
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.

refactor Sense.PartOfSpeech to use an object
2 participants