#Error: current transaction is aborted, commands ignored until end of transaction block

1 messages · Page 1 of 1 (latest)

loud marlin
#

Hey
I'm having some issues with a seed file.

It seems that when creating a media item, it doesn't let go of the transaction, so I when I go to seed it again, it comes back with,

const uploadMedia = async (
    req: PayloadRequest,
    payload: Payload,
    media: MediaSeed,
): Promise<Media> => {
    try {
        const image = await getFileByPath(path.resolve(dirname, media.path));
        return await payload.create({
            collection: 'media',
            file: image,
            data: {
                alt: media.alt,
                //caption: media.caption,
            },
            req,
        });
    } catch (error) {
        payload.logger.error(`Uploading media: ${error}`);
        throw error;
    }
};

export const seed = async ({
    payload,
    req,
}: {
    payload: Payload;
    req: PayloadRequest;
}): Promise<void> => {
    payload.logger.info('Seeding database...');

    // Clearing local media
    if (!env.isProduction) {
        payload.logger.info('Clearing media...');
        const mediaDir = path.resolve(dirname, '../../media');
        if (fs.existsSync(mediaDir)) {
            fs.rmSync(mediaDir, { recursive: true, force: true });
        }
    }

    // Clear Globals
    payload.logger.info('Clearing globals...');
    for (const global of globals) {
        await payload.updateGlobal({
            slug: global as GlobalSlug,
            data: {},
            req,
        });
    }

    // Clear Collections
    payload.logger.info('Clearing collections...');
    for (const collection of collections) {
        try {
            await payload.delete({
                collection: collection as CollectionSlug,
                where: {},
                req,
            });
        } catch (error) {
            payload.logger.warn(`Clearing collection ${collection}: ${error}`);
        }
    }
}
cunning drum
#

@loud marlin I think the message means that a transaction failed, so it becomes locked

loud marlin
#

Hmmm interesting thanks, can you see anything that could potentially cause this to fail? It’s 💯 the media upload

cunning drum
#

@loud marlin is this the correct way to upload a file via the local api?

#

the docs seem to use "filePath", etc

#

Oh you can do both

#

Hmm

loud marlin
#

Yeah it’s an interesting one. Very similar to the seed script that’s in payload itself, I’m just confused as to why it’s resulting in a failure