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

Callstack size exceeded on one to many relationship with customTypes #3026

Open
jmarshall9120 opened this issue Nov 15, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working data-schema Gen 2

Comments

@jmarshall9120
Copy link

Environment information

System:
  OS: Windows 11 10.0.22631
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 4.40 GB / 31.74 GB
Binaries:
  Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
  Yarn: 4.3.1 - C:\Program Files\nodejs\yarn.CMD
  npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
  pnpm: 9.13.1 - C:\Program Files\nodejs\pnpm.CMD
NPM Packages:
  @aws-amplify/auth-construct: 1.5.0
  @aws-amplify/backend: 1.7.0
  @aws-amplify/backend-auth: 1.4.0
  @aws-amplify/backend-cli: 1.4.2
  @aws-amplify/backend-data: 1.2.0
  @aws-amplify/backend-deployer: 1.1.9
  @aws-amplify/backend-function: 1.7.5
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.2
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.2
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.2.0
  @aws-amplify/plugin-types: 1.4.0
  @aws-amplify/sandbox: 1.2.5
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.8.2
  aws-cdk: 2.166.0
  aws-cdk-lib: 2.167.0
  typescript: 5.6.3
AWS environment variables:
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables

Data packages

nuxt-app@ M:\source\AdvancedStorageV3
├─┬ @aws-amplify/backend-cli@1.4.2
│ └─┬ @aws-amplify/schema-generator@1.2.5
│   └── @aws-amplify/graphql-schema-generator@0.11.2
└─┬ @aws-amplify/backend@1.7.0
  └─┬ @aws-amplify/backend-data@1.2.0
    └── @aws-amplify/data-construct@1.13.2

Description

TLDR - pushing out a deployment to sandbox causes a error when:
There is a one to many relationship between two customType()s using a.ref() & a.ref().array()
There is a 3rd model table using a.model()
A custom query references the a.model() table as dataSource and one of the a.customTypes() as returns() value.

Error Message:

Maximum call stack size exceeded
Caused By: Maximum call stack size exceeded

Resolution: Check your data schema definition for syntax and type errors.

Schema:

const schema = a.schema({
  MasterTenantTable: a.model({
    pk: a.string().required(),
    sk: a.string().required(),
    company_id: a.id(),
  })
  .authorization(allow=> [allow.publicApiKey()]),
  Tenant: a.customType({
    company: a.ref('Company'),
    company_id: a.id().required(),
  }),
  Company: a.customType({
    tenants: a.ref('Tenant').array(),
  }),
  getCompanyById: a.query()
    .arguments({company_id: a.id().required()})
    .returns(a.ref('Tenant').array())
    .authorization(allow=> [allow.authenticated()])
    .handler(a.handler.custom({
      dataSource: a.ref('MasterTenantTable'),
      entry: './company-resolvers/getCompanyById.js',
    })),
});

Repo reproduction link:
https://github.com/jmarshall9120/AmplifySchemaTesting

@chrisbonifacio
Copy link
Member

Hi @jmarshall9120 ! 👋 thanks for raising this issue!

I was able to consistently reproduce it on the latest versions of the amplify backend and data-schema packages.

CleanShot 2024-11-15 at 13 00 13@2x

i have marked this as a bug for the team to investigate.

@chrisbonifacio chrisbonifacio self-assigned this Nov 15, 2024
@chrisbonifacio chrisbonifacio added bug Something isn't working and removed pending-triage labels Nov 15, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Nov 15, 2024

Hi @jmarshall9120, in a first go through this it seems that you can break the cycle by removing one of the references like so:

  Tenant: a.customType({
    id: a.id().required(),
    company: a.ref('Company'),
  }),
  Company: a.customType({
    tenants: a.id().array(),
  }),

the other alternative workaround is to use a.model instead but that means extra DDB tables which may not fit your use case.

hopefully that helps to unblock you in the meantime while we continue looking into a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data-schema Gen 2
Projects
None yet
Development

No branches or pull requests

3 participants