fix(mediarequest): explicitly set mediaId when creating request (#2316)
* fix(mediarequest): explicitly set mediaId when creating Intermittent issue where media_request records were created with mediaId = NULL,causing TypeError when accessing request.media.tmdbId on the profile page. TypeORM's implicit relation-to-foreign-key mapping was failing intermittently. This sets the mediaId column explicitly and adds a guard to check to fail fast if media.id is not populated after save. fix #2315 * refactor: better logging when media id not found
This commit is contained in:
@@ -332,9 +332,16 @@ export class MediaRequest {
|
|||||||
if (requestBody.mediaType === MediaType.MOVIE) {
|
if (requestBody.mediaType === MediaType.MOVIE) {
|
||||||
await mediaRepository.save(media);
|
await mediaRepository.save(media);
|
||||||
|
|
||||||
|
if (!media.id) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to save media before creating request. Media type: ${requestBody.mediaType}, TMDB ID: ${requestBody.mediaId}, persisted media id: ${media.id}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const request = new MediaRequest({
|
const request = new MediaRequest({
|
||||||
type: MediaType.MOVIE,
|
type: MediaType.MOVIE,
|
||||||
media,
|
media,
|
||||||
|
mediaId: media.id,
|
||||||
requestedBy: requestUser,
|
requestedBy: requestUser,
|
||||||
// If the user is an admin or has the "auto approve" permission, automatically approve the request
|
// If the user is an admin or has the "auto approve" permission, automatically approve the request
|
||||||
status: user.hasPermission(
|
status: user.hasPermission(
|
||||||
@@ -442,9 +449,16 @@ export class MediaRequest {
|
|||||||
|
|
||||||
await mediaRepository.save(media);
|
await mediaRepository.save(media);
|
||||||
|
|
||||||
|
if (!media.id) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to save media before creating request. Media type: TV, TMDB ID: ${requestBody.mediaId}, is4k: ${requestBody.is4k}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const request = new MediaRequest({
|
const request = new MediaRequest({
|
||||||
type: MediaType.TV,
|
type: MediaType.TV,
|
||||||
media,
|
media,
|
||||||
|
mediaId: media.id,
|
||||||
requestedBy: requestUser,
|
requestedBy: requestUser,
|
||||||
// If the user is an admin or has the "auto approve" permission, automatically approve the request
|
// If the user is an admin or has the "auto approve" permission, automatically approve the request
|
||||||
status: user.hasPermission(
|
status: user.hasPermission(
|
||||||
@@ -521,6 +535,9 @@ export class MediaRequest {
|
|||||||
})
|
})
|
||||||
public media: Media;
|
public media: Media;
|
||||||
|
|
||||||
|
@Column({ name: 'mediaId', nullable: true })
|
||||||
|
public mediaId: number;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.requests, {
|
@ManyToOne(() => User, (user) => user.requests, {
|
||||||
eager: true,
|
eager: true,
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
|
|||||||
Reference in New Issue
Block a user