Repository navigation
Description
Describe the bug
With serverpod start or serverpod generate --watch running, a git pull (or a branch switch) that brings a model change together with its regenerated code and an endpoint that uses the change makes generation fail:
Endpoint analysis skipped due to invalid Dart syntax. Please review and correct the syntax errors.
.../lib/src/notes/note_endpoint.dart Error: The named parameter 'tag' isn't defined.
The generated files are rewritten without that endpoint. Every later generation in the same session fails the same way, even after the generated files are restored from git. Restarting the command fixes it, and a one-shot serverpod generate on the same tree succeeds.
To reproduce
- In a project created with
serverpod create, addlib/src/notes/note.spy.yaml:andclass: Note fields: text: String
lib/src/notes/note_endpoint.dart:Runimport 'package:serverpod/serverpod.dart'; import '../generated/protocol.dart'; class NoteEndpoint extends Endpoint { Future<Note> get(Session session) async => Note(text: 'a'); }
serverpod generateand commit everything, generated files included. - On a second branch, add
tag: String?to the model, change the endpoint toNote(text: 'a', tag: 'b'), runserverpod generateand commit everything. - Check out the first commit and run
serverpod start(orserverpod generate --watch). - Once it is watching,
git merge --ff-onlythe second branch.
Generation fails with the error above, and endpoints.dart, protocol.yaml and the client's client.dart no longer contain the note endpoint. Editing a comment in note_endpoint.dart triggers another generation, which fails the same way.
If the second commit leaves out the generated files, the same steps work.
Expected behavior
After the pull, watch mode generates from the tree as it is on disk, the same as a one-shot serverpod generate.
Library version
serverpod 4.1.2 (CLI and packages), also on main at b1dc2ee. Dart 3.14.0.
Platform information
macOS 27.2.1 (arm64).
Additional context
From reading the code:
- Since perf: Remove CLI code generation heuristics and improve performance #5825, generation refreshes the analysis context only with the generated model files it writes, and it does not write a file whose content is already on disk.
- After the pull, the regenerated model on disk already matches what generation produces, so it is not written, and the analyzers keep the version they read before the pull.
- Models whose generated file imports
protocol.dartescape this, because refreshing theprotocol.dartstub evicts them. Leaf models likeNoteabove do not. - The watch loops pass only source and model files to generation, so a changed generated file does not reach the analyzers that way either.
A fix that compares the generated model files with what the analysis context was last given, and refreshes the ones that differ, covers both commands. I have one ready with a test and benchmark numbers.
How experienced are you with this library?
None
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity