Skip to content

sql/no-client-schema is generated but never compiled #5

Closed

Description

@lesomnus

Corrected. The first version of this said nothing in the repository
generates with the flag on. That is wrong: entc/gen/graph_test.go builds a
graph with Features: AllFeatures, and #4 appended FeatureNoClientSchema to
that list, so TestGraph_Gen renders the flag-on templates on every
go test ./entc/gen/. The gap is narrower than stated and is below.

sql/no-client-schema (#4) drops Client.Schema and the <pkg>/migrate import
with it, so a binary that never migrates does not link Atlas.

What is covered

TestGraph_Gen runs graph.Gen() with every feature on, so the flag-on branch
of client.tmpl and enttest.tmpl is rendered, and Gen runs imports.Process
over the result (entc/gen/graph.go:1167). A template that fails to execute, or
that produces Go which does not parse, fails the test.

What is not

That test only os.Stats the files it expects. Nothing compiles them.

  • A type error passes. enttest.tmpl renders migrate.NewSchema(c.Driver())
    under this flag; if Client.Driver() were renamed or its signature changed,
    the file would render, parse and format, and every job would stay green.
  • A stale import passes silently, because imports.Process removes it rather
    than reporting it.

The generate job compiles nothing extra either — every package in this
repository is generated with the flag off, which is what that job pins.

What would close it

A small integration package generated with the flag on, alongside the ones
generated without it: a schema, a generate.go carrying the feature, and a test
that creates the schema the way a caller must under this flag.

if err := migrate.NewSchema(drv).Create(ctx); err != nil {
	...
}

Then both paths are compiled on every run and the generate job holds them both.

Also

entc/gen/template/migrate/migrate.tmpl:70 documents client.Schema.WriteTo in
a comment. Under this flag there is no client.Schema, so the example in the
generated package names something that package does not have.

Activity

  1. changed the title [-]sql/no-client-schema has no test that generates with it on[/-] [+]sql/no-client-schema is generated but never compiled[/+] on Sep 6, 2026
  2. lesomnus commented on Sep 6, 2026

    @lesomnus
    MemberAuthor

    Closed by 2ee2016.

    entc/integration/noclientschema is generated with the flag on and is an ordinary package, so go build compiles it and the generate job rewrites it with the flag on and fails if it drifts. Two tests: one runs the migration the way a caller has to when Client does not carry it, the other asserts by reflection that Client has no Schema field — checked against the flag off, where it fails.

    CI on that commit is green across all four jobs, integration included (eighteen packages now, on the six engines).

    The stale example in entc/gen/template/migrate/migrate.tmpl:70 — a comment naming client.Schema.WriteTo, which does not exist under this flag — is left as is. It is a comment in the generated migrate package, which the flag does not change, and it reads correctly for every configuration but this one.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions