xorm can't handle nil return values #1844

Closed
opened 2020-12-23 13:58:32 +00:00 by kolaente · 3 comments

I have a function like this one:

func GetListByID(s *xorm.Session, listID int64) (list *List, err error) {
	_, err = s.Where("id = ?", listID).Get(list)
	return
}

Calling it fails with a Table not found error.

I looked into it and it seems like the table name is not set and thus the error is returned.

However, when I initialize the struct like this, it works:

func GetListByID(s *xorm.Session, listID int64) (list *List, err error) {
	list = &List{}
	_, err = s.Where("id = ?", listID).Get(list)
	return
}

Is that a bug or a limitation in go?

I have a function like this one: ```go func GetListByID(s *xorm.Session, listID int64) (list *List, err error) { _, err = s.Where("id = ?", listID).Get(list) return } ``` Calling it fails with a `Table not found` error. I looked into it and it seems like the table name is not set and thus the error is returned. However, when I initialize the struct like this, it works: ```go func GetListByID(s *xorm.Session, listID int64) (list *List, err error) { list = &List{} _, err = s.Where("id = ?", listID).Get(list) return } ``` Is that a bug or a limitation in go?
Owner

@kolaente I think it's a limitation of xorm. XORM always assume that the parameter of Get is a not an empty pointer.

@kolaente I think it's a limitation of xorm. XORM always assume that the parameter of `Get` is a not an empty pointer.
Author

Do you know if there is a way for xorm to check if that's really the case? I think it would be useful to throw an error in that case - it took me a while to find the cause of the issue.

Do you know if there is a way for xorm to check if that's really the case? I think it would be useful to throw an error in that case - it took me a while to find the cause of the issue.
Owner

Yes, the error should be more clear. I will send a PR to do that.

Yes, the error should be more clear. I will send a PR to do that.
lunny closed this issue 2021-03-23 13:48:59 +00:00
lunny closed this issue 2021-03-23 13:48:59 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1844
No description provided.