xorm can't handle nil return values #1844

Closed
opened 4 months ago 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.
Poster

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 referenced this issue from a commit 4 weeks ago
lunny closed this issue 4 weeks ago
lunny closed this issue 4 weeks ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.