Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.last() returns list #86

Open
dvnstrcklnd opened this issue Nov 18, 2020 · 2 comments
Open

Model.last() returns list #86

dvnstrcklnd opened this issue Nov 18, 2020 · 2 comments

Comments

@dvnstrcklnd
Copy link
Contributor

The Model.last() method returns a list. It seems like it should return a single object.

last_sample = session.Sample.last()
print("{}: {}".format(last_sample.name, last_sample.description))

produces

Traceback (most recent call last):
  File "load_samples.py", line 11, in <module>
    print("{}: {}".format(last_sample.name, last_sample.description))
AttributeError: 'list' object has no attribute 'name'
@cashmonger
Copy link
Contributor

I would also expect Model.last to return a single object. I can change things so it does, but, in the interim, there is also a "one" method you can call that will return the last item.

last_sample = session.Sample.one()
print("{}: {}".format(last_sample.name, last_sample.description))
GS apater F: subpool adapter with linker for Agilent libraries

@jvrana
Copy link
Contributor

jvrana commented Dec 16, 2020

The way it is now, .last(n) was intended to always return a list, but it doesn't have to be that way, so it may make sense to change it to

  • Sample.last() - return last Sample (or None if there are no Samples)
    -Sample.last(1) - return last Sample as a list
  • Sample.last(10) return last 10 Samples as a list
  • Sample.first() - return first Sample (or None if there are no Samples)
  • Sample.first(1) - return first Sample as a list
  • Sample.first(10) return first 10 Samples as a list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants