-
Notifications
You must be signed in to change notification settings - Fork 90
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
Refactor photometry handler #2648
Conversation
@profjsb It looks crazy pants, but this is just removing the 4 space indent for most of the functions at the start of the photometry handler and calling them directly. |
Fix test: test_sources.py::test_sources_include_detection_stats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great but I'm still worried about the LOCKs. Looking at https://stackoverflow.com/a/47256217 it seems to make sense for us to put those LOCK lines inside a try statement then in the except make sure we do a DBSession.rollback()
to make sure we release the lock.
if "altdata" in data and not data["altdata"]: | ||
del data["altdata"] | ||
if "altdata" in data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see how line 184 ever evaluates to True given the lines above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a = []
assert not a
So checks for empty list?
@profjsb So basically
=> |
At minimum, the lock would need to be wrapped in a I believe we have duplication checks on the DB level, so another option is to just do the check, try the insert, and catch the error if it fails? |
@stefanv Can you help me understand how your second option is different from above? |
@mcoughlin I looked at your snippet again and I think the As an aside, we are now able to use the new SQLAlchemy syntax:
|
@stefanv can you see if you are happier with this? I put your try except and with DBSession() as session around the LOCK bits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mcoughlin! Looks good. There's just that one docstring left hanging, and a question re: multiple types of session objects.
skyportal/handlers/api/photometry.py
Outdated
|
||
def add_external_photometry(json, user): | ||
""" | ||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring seems to be misplaced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does that mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, because now we just return the log()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it looks like a handler (GET
, POST
, PUT
, etc.) docstring in YAML, whereas I would expect a standard Python function docstring that describes the two arguments: json
and user
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, hopefully more clear now?
@@ -43,6 +45,10 @@ | |||
_, cfg = load_env() | |||
|
|||
|
|||
log = make_log('api/photometry') | |||
Session = scoped_session(sessionmaker(bind=DBSession.session_factory.kw["bind"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still used? Do we need both DBSession and Session?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have usually seen us using DBSession() in the APIs and Session when called external to the APIs (like when we do the IOSync stuff).
…nto photometry_handler
skyportal/handlers/api/photometry.py
Outdated
) | ||
except Exception as e: | ||
session.rollback() | ||
return log(f"Unable to post photometry: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log does not return anything
Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
@profjsb please merge if comfortable with this now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. We should make another issue to look into why we get 400 and 500 sometimes (not suppose to happen).
@@ -2258,7 +2263,7 @@ def test_problematic_photometry_1276( | |||
data=payload, | |||
token=super_admin_token, | |||
) | |||
assert status in [401, 500] | |||
assert status in [400, 500] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is 400 getting returned anywhere? It's worth understanding this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP 500 is internal server error. BAD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that should be investigated by scouring those logs.
This PR refactors the photometry handler to enable posting from a different API (useful for the ATLAS and PS1 PRs).