go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.48k stars 3.9k forks source link

When I do Find(&obj) in contex cancelled state, it falls into panic state v1.25.11 #7119

Closed ozkansen closed 6 days ago

ozkansen commented 1 month ago

When I do Find(&obj) in contex cancelled state, it falls into panic state. This situation started to occur with v1.25.11.

Example code:

func (p PlaylistRepository) GetPlaylistItemsByPlaylistID(ctx context.Context, id uint, limit, offset int) (result *models.PlaylistItemWithMediaList, err error) {
    var (
        dbPlaylistItems []dbmodels.PlaylistItemWithMedia
        count           int64
    )
    if err = p.db.WithContext(ctx).
        Select(
            "pi.created_at as item_created_at",
            "pi.detail as item_detail",
            "pi.id as item_id",
            "pi.\"order\" as item_order",
            "pi.playlist_id as item_playlist_id",
            "pi.fixed as item_fixed",
            "m.id as media_id",
            "m.uuid as media_uuid",
            "m.ext as media_ext",
            "m.url as media_url",
            "m.thumbnail as media_thumbnail",
            "m.title as media_title",
            "m.type as media_type",
            "m.storage_type as media_storage_type",
            "m.size as media_size",
            "m.customer_id as media_customer_id",
            "m.user_id as user_id",
            "m.info as media_info",
            "m.checksum as media_checksum",
            "u.full_name as user_full_name",
            "u.job_title as user_job_title",
            "u.email as user_email",
            "u.mobile_number as user_mobile_number",
            "u.department as user_department",
        ).
        Table("playlist_items pi").
        Joins(
            "left join media m on m.id = pi.media_id "+
                "left join users u on m.user_id = u.id",
        ).
        Where("pi.playlist_id = ?", id).
        Count(&count).Limit(limit).Offset(offset).
        Find(&dbPlaylistItems).Error; err != nil {
        err = fmt.Errorf("get playlist items by playlist id / find : %w", err)
        return
    }

    playlistItems := make([]*models.PlaylistItemWithMedia, 0, len(dbPlaylistItems))

    for i := range dbPlaylistItems {
        var pm *models.PlaylistItemWithMedia

        if pm, err = dbPlaylistItems[i].To(); err != nil {
            err = fmt.Errorf("get playlist items by playlist id / convert to : %w", err)
            return
        }

        playlistItems = append(playlistItems, pm)
    }

    result = &models.PlaylistItemWithMediaList{
        Items:  playlistItems,
        Count:  count,
        Limit:  limit,
        Offset: offset,
    }
    return
}
github-actions[bot] commented 1 month ago

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

github-actions[bot] commented 1 month ago

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking