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

[TM-1531] prevent error on metadata null #35

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

egrojMonroy
Copy link
Collaborator

Error was triggering on trying to get entity_name from metadata

@egrojMonroy egrojMonroy requested a review from roguenet December 26, 2024 20:24
Copy link

nx-cloud bot commented Dec 26, 2024

View your CI Pipeline Execution ↗ for commit 82a0d35.

Command Status Duration Result
nx run-many -t test --coverage --passWithNoTests ✅ Succeeded 9s View ↗
nx test database --no-cache ✅ Succeeded <1s View ↗
nx run-many -t lint build ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2024-12-26 20:52:20 UTC

@@ -111,7 +111,7 @@ export class DelayedJobsController {
job.isAcknowledged = attributes.isAcknowledged;
await job.save();

const entityName = (job.metadata as { entity_name?: string }).entity_name;
const entityName = job.metadata ? (job.metadata as { entity_name?: string }).entity_name : null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should not be relying on any particular structure to the metadata. I think this would be cleaner:

const entityName = job.metadata?.entity_name ?? "";

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't use it that way because I had this error:
Property 'entity_name' does not exist on type 'object'.ts(2339)

Because the definition is like this:

 @AllowNull
  @Column(JSON)
  metadata: object | null;

Some options to fix it:

const entityName = (job.metadata as any)?.entity_name ?? "";

or:

@AllowNull
@Column(JSON)
metadata: any | null;

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.

2 participants