Field hooks beforeOperation and afterOperation not running with default value

Open
#9,382 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #10040 by @Tyagiquamar — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, sqlite, typescript
Domain
backend

Research direction

Start by reproducing the shown Material list configuration with the SQLite provider and trace the field hook lifecycle when order keeps its default value. No repository file or test path is named; locate the existing field-hook or default-value tests, and consider the issue resolved when beforeOperation and afterOperation run for default-valued fields as they do for changed values.

Written by the indexing model from the issue text.

Description

To reproduce:

  1. Create new Keystone app with the following config:
import { config, list } from "@keystone-6/core";
import { allowAll } from "@keystone-6/core/access";
import { text, integer } from "@keystone-6/core/fields";
import { session } from "./auth";

export default config({
  db: {
    provider: "sqlite",
    url: "file:./keystone.db",
  },
  lists: {
    Material: list({
      access: allowAll,
      fields: {
        name: text({ validation: { isRequired: true }, isIndexed: "unique" }),
        order: integer({
          validation: {
            isRequired: false,
            min: 1,
          },
          defaultValue: 1,
          hooks: {
            resolveInput: async () => console.log("resolveInput"),
            beforeOperation: async () => console.log("beforeOperation"),
          },
        }),
      },
    }),
  },
  session,
  ui: {
    isAccessAllowed: () => true,
  },
});
  1. Create new entity, without changing the default value
  2. Observe the stdout having only "resolveInput" being logged

Note: If the value of order field is different from default value, the hooks are firing as expected

Expectation:

Fields with default values should not behave any different from fields with default values.

Using:
node 20.18.0
keystone-6/core 6.3.0

Dominant language
TypeScript
Stars
10k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
38

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from keystonejs/keystone

All issues in keystonejs/keystone

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.