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

Impose restrictions on name field #291

Merged
merged 3 commits into from
Apr 14, 2024

Conversation

mwcraig
Copy link
Contributor

@mwcraig mwcraig commented Apr 13, 2024

I realized while working on the form for entering Camera and other named objects that it allowed a bunch of bad names, like "" or " ". Since leading or trailing whitespace in a name also seemed like a bad idea, this PR adds (and tests) this constraint on the name field:

  • Must be one or more non-whitespace characters
  • Cannot have leading or trailing whitespace

A quick review on this would be helpful...

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 71.86%. Comparing base (f421224) to head (f927559).
Report is 2 commits behind head on main.

Files Patch % Lines
stellarphot/io/tess.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
- Coverage   72.24%   71.86%   -0.38%     
==========================================
  Files          26       26              
  Lines        3210     3220      +10     
==========================================
- Hits         2319     2314       -5     
- Misses        891      906      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

I think this looks good and ready to merge, ALTHOUGH a few of the code changes in this commit have nothing to do with checking the name field for spaces and instead seem to be related to handling TESS catalog timeouts...

)
if result.status_code != 200:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this has to do with name field restrictions. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we were getting a test failure on two tests because of this

@@ -3,7 +3,7 @@

import pytest
from astropy.coordinates import SkyCoord
from requests import ConnectionError
from requests import ConnectionError, ReadTimeout
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this has to do with allowing timeout of TESS access attempt, not the name field restrictions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct...I wanted to make the lights green

if not value.strip():
raise ValueError("name must not be empty or contain only whitespace.")

if not re.search(r"^\S$|^\S.*\S$", value):
Copy link
Contributor

Choose a reason for hiding this comment

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

So you are matching a SINGLE non-whitespace character as the string name or any string that starts and ends with non-whitespace characters? I guess this makes sense, as I think of ways to avoid leading or trialing spaces... you have to allow for the possibility of a single character or multiple characters. It does look odd, but the logic is sound.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is the intent. I thought about just stripping out whitespace silently but it seemed but to flag it instead.

@@ -221,9 +249,10 @@ class Camera(BaseModelWithTableRep):
model_config = MODEL_DEFAULT_CONFIGURATION

name: Annotated[
str,
NonEmptyStr,
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me a bit, but I see this is now using that NonEmptyStr validator you set up above...

@mwcraig mwcraig merged commit bd23f25 into feder-observatory:main Apr 14, 2024
9 checks passed
@mwcraig mwcraig deleted the impose-restrictions-on-name branch April 14, 2024 14:23
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