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

Transactionize the Study, StudyPerson and Reference #1333

Merged

Conversation

josenavas
Copy link
Contributor

Modifies the Study, StudyPerson and Reference objects to use transactions

Few comments:

  • Study.create was not checking for duplicates. A check and a test have been added.
  • StudyPerson.create was not raising duplicate error in case of duplicate, just returned the existing object. Changed for consistency with the rest of the system If it doesn't return the already existent object there isn't a way to retrieve the existent one from the DB. Created an issue to solve later Make StudyPerson.create raise in case of duplicate #1336
  • StudyPerson.exists was missing tests. Added.

@josenavas josenavas added this to the Alpha 0.2 milestone Jul 7, 2015
@josenavas josenavas mentioned this pull request Jul 7, 2015
28 tasks
"reference_id = %s".format(self._table), (self._id,))[0]
_, basefp = get_mountpoint('reference')[0]
with TRN:
sql = """SELECT reference_name FROM qiita.{0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can be done with the convert_from_id function, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not converting from any id, is accessing to the reference_name attribute of the reference class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it.

@josenavas
Copy link
Contributor Author

@squirrelo I've addressed your comments

@antgonza can you review this one?

with TRN:
# Get the status of all its processed data
sql = """SELECT processed_data_status
FROM qiita.processed_data_status pds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none blocking but you are missing a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

inv = conn_handler.execute_fetchone(sql, (self._id, ))
return inv[0] if inv is not None else inv
with TRN:
sql = """SELECT investigation_id FROM qiita.investigation_study
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be better to sort by investigation_id and limit 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is needed. If it exists, it will be only one. The inv[0][0] is because if it doesn't exist, TRN.execute_fetchindex returns an empty list, but if there is a value it will return [[inv_id]], and doesn't matter how I change the query, since this is because the transaction internally is doing a fetchall.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A study can be part of more than one investigation though, right? Hence the investigation_study join table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. To be fair we have not been using investigation, and I think that right now is not needed given that we can have multiple prep templates in a single study.

Investigation was useful in the old database, were we had to create a study for each prep template... but right now we can create a single study and have everything there. And if multiple studies belong to "an investigation" that is a meta-analysis.

I think this is another discussion and this code is duplicating the functionality of the previous code, so if there are no more comments, we should merge this and keep moving forward with the transactionization of the system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Should open an issue discussing if we need the investigation object.

@antgonza
Copy link
Member

antgonza commented Jul 7, 2015

minor comments

@josenavas
Copy link
Contributor Author

Addressed/answered

@antgonza
Copy link
Member

antgonza commented Jul 7, 2015

👍

@squirrelo
Copy link
Contributor

One question.

@squirrelo
Copy link
Contributor

👍

squirrelo added a commit that referenced this pull request Jul 7, 2015
Transactionize the Study, StudyPerson and Reference
@squirrelo squirrelo merged commit 09149f5 into qiita-spots:transaction Jul 7, 2015
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

Successfully merging this pull request may close these issues.

3 participants