Error 500 in web interface when trying to change branch

After upgrading Gitea from 1.8.3 to 1.9.x or 1.10.3 I’m getting error 500 when trying to switch to another branch than master. Using command line, I can create and switch branches without any problems.

My environment:
OS: FreeBSD 11.3
Gitea: 1.10.3
Git: 2.25.1
Database: MySQL 5.7.29

The gitea.log states an error “GetBranchCommit: object not found”, but I have no clue about the reason. The following snippet shows the log output for a request to change the branch currently displayed in the browser:

2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `lower_name`, `name`, `full_name`, `email`, `keep_email_private`, `email_notifications_preference`, `passwd`, `passwd_hash_algo`, `must_change_password`, `login_type`, `login_source`, `login_name`, `type`, `location`, `website`, `rands`, `salt`, `language`, `description`, `created_unix`, `updated_unix`, `last_login_unix`, `last_repo_visibility`, `max_repo_creation`, `is_active`, `is_admin`, `allow_git_hook`, `allow_import_local`, `allow_create_organization`, `prohibit_login`, `avatar`, `avatar_email`, `use_custom_avatar`, `num_followers`, `num_following`, `num_stars`, `num_repos`, `num_teams`, `num_members`, `visibility`, `repo_admin_change_team_access`, `diff_view_style`, `theme` FROM `user` WHERE `id`=? LIMIT 1 []interface {}{4} - took: 1.676713ms
2020/02/18 14:57:08 ...s/context/context.go:330:func1() [D] Session ID: e631d5692a501d48
2020/02/18 14:57:08 ...s/context/context.go:331:func1() [D] CSRF Token: 7ETOydR8a3bmdwQIa9UJX0A5RDQ6MTU4MjAzMTQzNzg0MTc1OTA5MQ
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT count(*) FROM `notification` WHERE (user_id = ?) AND (status = ?) []interface {}{4, 0x1} - took: 830.28µs
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `owner_id`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` WHERE `owner_id`=? AND `lower_name`=? LIMIT 1 []interface {}{4, "library"} - took: 848.123µs
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `repo_id`, `user_id`, `mode` FROM `collaboration` WHERE `repo_id`=? AND `user_id`=? LIMIT 1 []interface {}{7, 4} - took: 559.23µs
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `repo_id`, `type`, `config`, `created_unix` FROM `repo_unit` WHERE (repo_id = ?) []interface {}{7} - took: 713.883µs
2020/02/18 14:57:08 ...s/repo_permission.go:154:func1() [T] Permission Loaded for 824703262176:artanis in 824703262256:artanis/library:
	Permissions: AccessMode: 824703656032:owner, 5 Units, 0 UnitsMode(s): [ 
	Units[0]: ID: 824703262352 RepoID: 824703262384 Type: 824703656064:UnitTypeCode Config: {}
	Units[1]: ID: 824703262448 RepoID: 824703262480 Type: 824703656096:UnitTypeIssues Config: {"EnableTimetracker":false,"AllowOnlyContributorsToTrackTime":true,"EnableDependencies":true}
	Units[2]: ID: 824703262544 RepoID: 824703262576 Type: 824703656128:UnitTypePullRequests Config: {"IgnoreWhitespaceConflicts":false,"AllowMerge":true,"AllowRebase":true,"AllowRebaseMerge":true,"AllowSquash":true}
	Units[3]: ID: 824703262640 RepoID: 824703262672 Type: 824703656160:UnitTypeReleases Config: {}
	Units[4]: ID: 824703655952 RepoID: 824703655984 Type: 824703656192:UnitTypeWiki Config: {} ]
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT count(*) FROM `release` WHERE repo_id=? AND is_draft=? []interface {}{7, false} - took: 704.034µs
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT * FROM `user` INNER JOIN `team_user` ON `team_user`.org_id=`user`.id INNER JOIN `team` ON `team`.id=`team_user`.team_id WHERE (`team_user`.uid=?) AND (`team`.authorize=?) ORDER BY `user`.`name` ASC []interface {}{4, 4} - took: 1.222547ms
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `user_id`, `repo_id` FROM `watch` WHERE `user_id`=? AND `repo_id`=? LIMIT 1 []interface {}{4, 7} - took: 501.744µs
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `uid`, `repo_id` FROM `star` WHERE `uid`=? AND `repo_id`=? LIMIT 1 []interface {}{4, 7} - took: 388.676µs
2020/02/18 14:57:08 ...ules/context/repo.go:648:func1() [E] GetBranchCommit: object not found
2020/02/18 14:57:08 ...s/context/context.go:139:HTML() [D] Template: status/500
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `lower_name`, `name`, `full_name`, `email`, `keep_email_private`, `email_notifications_preference`, `passwd`, `passwd_hash_algo`, `must_change_password`, `login_type`, `login_source`, `login_name`, `type`, `location`, `website`, `rands`, `salt`, `language`, `description`, `created_unix`, `updated_unix`, `last_login_unix`, `last_repo_visibility`, `max_repo_creation`, `is_active`, `is_admin`, `allow_git_hook`, `allow_import_local`, `allow_create_organization`, `prohibit_login`, `avatar`, `avatar_email`, `use_custom_avatar`, `num_followers`, `num_following`, `num_stars`, `num_repos`, `num_teams`, `num_members`, `visibility`, `repo_admin_change_team_access`, `diff_view_style`, `theme` FROM `user` WHERE `id`=? LIMIT 1 []interface {}{4} - took: 1.204913ms
2020/02/18 14:57:08 ...s/context/context.go:330:func1() [D] Session ID: e631d5692a501d48
2020/02/18 14:57:08 ...s/context/context.go:331:func1() [D] CSRF Token: 7ETOydR8a3bmdwQIa9UJX0A5RDQ6MTU4MjAzMTQzNzg0MTc1OTA5MQ
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT count(*) FROM `notification` WHERE (user_id = ?) AND (status = ?) []interface {}{4, 0x1} - took: 774.001µs
2020/02/18 14:57:08 ...uters/user/avatar.go:25:Avatar() [D] Asked avatar for user artanis and size -1
2020/02/18 14:57:08 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `lower_name`, `name`, `full_name`, `email`, `keep_email_private`, `email_notifications_preference`, `passwd`, `passwd_hash_algo`, `must_change_password`, `login_type`, `login_source`, `login_name`, `type`, `location`, `website`, `rands`, `salt`, `language`, `description`, `created_unix`, `updated_unix`, `last_login_unix`, `last_repo_visibility`, `max_repo_creation`, `is_active`, `is_admin`, `allow_git_hook`, `allow_import_local`, `allow_create_organization`, `prohibit_login`, `avatar`, `avatar_email`, `use_custom_avatar`, `num_followers`, `num_following`, `num_stars`, `num_repos`, `num_teams`, `num_members`, `visibility`, `repo_admin_change_team_access`, `diff_view_style`, `theme` FROM `user` WHERE `lower_name`=? LIMIT 1 []interface {}{"artanis"} - took: 1.060362ms
2020/02/18 14:57:09 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT `id`, `lower_name`, `name`, `full_name`, `email`, `keep_email_private`, `email_notifications_preference`, `passwd`, `passwd_hash_algo`, `must_change_password`, `login_type`, `login_source`, `login_name`, `type`, `location`, `website`, `rands`, `salt`, `language`, `description`, `created_unix`, `updated_unix`, `last_login_unix`, `last_repo_visibility`, `max_repo_creation`, `is_active`, `is_admin`, `allow_git_hook`, `allow_import_local`, `allow_create_organization`, `prohibit_login`, `avatar`, `avatar_email`, `use_custom_avatar`, `num_followers`, `num_following`, `num_stars`, `num_repos`, `num_teams`, `num_members`, `visibility`, `repo_admin_change_team_access`, `diff_view_style`, `theme` FROM `user` WHERE `id`=? LIMIT 1 []interface {}{4} - took: 1.066465ms
2020/02/18 14:57:09 ...s/context/context.go:330:func1() [D] Session ID: e631d5692a501d48
2020/02/18 14:57:09 ...s/context/context.go:331:func1() [D] CSRF Token: 7ETOydR8a3bmdwQIa9UJX0A5RDQ6MTU4MjAzMTQzNzg0MTc1OTA5MQ
2020/02/18 14:57:09 .../xorm/session_raw.go:76:queryRows() [I] [SQL] SELECT count(*) FROM `notification` WHERE (user_id = ?) AND (status = ?) []interface {}{4, 0x1} - took: 856.48µs
2020/02/18 14:57:09 ...s/context/context.go:139:HTML() [D] Template: pwa/serviceworker_js

Does anyone have an idea what’s going on and how to solve this issue?

Best regards,
Oliver

After having set up a fresh instance of Gitea 1.10.3 on a VM I could narrow down the problem to branch names. It seems that if a branch name contains special chars like the slash character (/), switching to such a branch in the UI results in error 500.

With Gitea 1.8.3 this problem does not occur.

I tried to reproduce this at try.gitea.io with no success.

Best regards,
Oliver