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

Fix #921: Truncate latlng to 30 chars #926

Merged
merged 5 commits into from
Jan 21, 2024

Conversation

dostogircse171
Copy link
Contributor

This pull request fixes #921 the DataError encountered when saving latlng values longer than 30 characters.
It modifies the save method of the EventApplication model to truncate the latlng value to 30 characters, ensuring data integrity without altering the database schema.

@@ -129,7 +129,8 @@ def __str__(self):

def save(self, *args, **kwargs):
if not self.latlng:
self.latlng = get_coordinates_for_city(self.city, self.get_country_display())
latlng_coord = get_coordinates_for_city(self.city, self.get_country_display())
self.latlng = latlng_coord[:30] # Truncate to 30 characters to match the database field limit
Copy link
Contributor

Choose a reason for hiding this comment

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

If we get values like this (-74.80111590000001, -74.80111590000001) of which each value is 19 characters, we would truncate this and have the first value remain 19 characters while the second value becomes -74.80111 is 9 characters long. It would be better to format the values in the get_coordinates_for_city()and limit the number of decimals places for each so that they are of equal length, making consideration for the possible-in the values. The function is here https://github.com/DjangoGirls/djangogirls/blob/main/core/utils.py#L18 incore/utils.py`.

Thanks for your work on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much for the review and letting me know @amakarudze
I Got it. Let me work on this and I will get back soon.

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 have made those changes. Please let me know if any changes are required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, sorry for not getting back to you earlier on. Just have one more comment below.

Copy link
Contributor

Choose a reason for hiding this comment

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

One more change, can you truncate to 7 decimal places, tests are failing because the values in the tests are set to 7 decimal places while your changes truncate to 6 decimal places. Truncating to 7 decimal places should fix this. Also use double quotes for the f string to address ruff issues.

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 sure. Will do. Thank you

Copy link
Contributor

@amakarudze amakarudze left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @dostogircse171 !

core/utils.py Outdated
return f'{data["lat"]}, {data["lon"]}'
formatted_lat = "{:.6f}".format(float(data["lat"]))
formatted_lon = "{:.6f}".format(float(data["lon"]))
return f'{formatted_lat}, {formatted_lon}'
Copy link
Contributor

Choose a reason for hiding this comment

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

The ruff build is failing because of the single quotes here. May you please address this so we can merge this pull request. Sorry for taking so much time to review again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @amakarudze ,
Thank you for your review. No problem let me fix this and I will update the code soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're welcome. Thanks for your work on this.

Copy link
Contributor

@amakarudze amakarudze left a comment

Choose a reason for hiding this comment

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

Please address the 7 decimal places and single quotes issues. Thanks!

@dostogircse171
Copy link
Contributor Author

Please address the 7 decimal places and single quotes issues. Thanks!

This is done. Let me know if anything else is required here.
Thank you

Copy link
Contributor

@amakarudze amakarudze left a comment

Choose a reason for hiding this comment

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

LGTM!

@dostogircse171
Copy link
Contributor Author

@amakarudze I think we also need to adjust test_utils.py to match new changes.

@amakarudze
Copy link
Contributor

amakarudze commented Jan 21, 2024

@amakarudze I think we also need to adjust test_utils.py to match new changes.

Yeah @dostogircse171 , true I just noticed it has 8 decimal places, so removing 1 each should work. Sorry about that.

@dostogircse171
Copy link
Contributor Author

@amakarudze I think we also need to adjust test_utils.py to match new changes.

Yeah @dostogircse171 , true I just noticed it has 8 decimal places, so removing 1 each should work. Sorry about that.

@amakarudze I can see inside test_utils.py file same function
test_day_before_deadline() has been used 3 times with the same values. is this a mistake or it has some purpose?

Copy link

codecov bot commented Jan 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a308b5b) 80.28% compared to head (8131aef) 81.02%.
Report is 72 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #926      +/-   ##
==========================================
+ Coverage   80.28%   81.02%   +0.74%     
==========================================
  Files          95       95              
  Lines        2845     2862      +17     
  Branches      273      269       -4     
==========================================
+ Hits         2284     2319      +35     
+ Misses        503      492      -11     
+ Partials       58       51       -7     
Files Coverage Δ
core/utils.py 88.46% <100.00%> (+7.61%) ⬆️

... and 17 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a308b5b...8131aef. Read the comment docs.

@amakarudze amakarudze merged commit a689641 into DjangoGirls:main Jan 21, 2024
6 checks passed
@amakarudze
Copy link
Contributor

@amakarudze I think we also need to adjust test_utils.py to match new changes.

Yeah @dostogircse171 , true I just noticed it has 8 decimal places, so removing 1 each should work. Sorry about that.

@amakarudze I can see inside test_utils.py file same function test_day_before_deadline() has been used 3 times with the same values. is this a mistake or it has some purpose?

@dostogircse171 i have no idea, will have to look into it first before making any changes. Thanks for your work on this, I have merged the PR and some of my issues will go away because of this change!

@dostogircse171 dostogircse171 deleted the truncate-latlng-fix-921 branch January 21, 2024 17:50
@dostogircse171
Copy link
Contributor Author

@amakarudze I think we also need to adjust test_utils.py to match new changes.

Yeah @dostogircse171 , true I just noticed it has 8 decimal places, so removing 1 each should work. Sorry about that.

@amakarudze I can see inside test_utils.py file same function test_day_before_deadline() has been used 3 times with the same values. is this a mistake or it has some purpose?

@dostogircse171 i have no idea, will have to look into it first before making any changes. Thanks for your work on this, I have merged the PR and some of my issues will go away because of this change!

@amakarudze Thank you very much. It's a pleasure to work on this task. Is there any other task you can recommend me to pick next?

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.

DataError: value too long for type character varying(30)
2 participants