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

Index error - string index out of range #12

Closed
ejk3052 opened this issue Jun 9, 2020 · 10 comments
Closed

Index error - string index out of range #12

ejk3052 opened this issue Jun 9, 2020 · 10 comments
Labels
more-information-needed Further information is needed for resolving this issue

Comments

@ejk3052
Copy link

ejk3052 commented Jun 9, 2020

Hello,

I get index error - string index out of range, when I save the form
Screenshot 2020-06-09 at 7 50 15 PM
Screenshot 2020-06-09 at 7 48 52 PM

@simon-the-shark
Copy link
Owner

Do you use the latest version of the package?

@simon-the-shark
Copy link
Owner

Could you describe to me what have you exactly done in this example? I guess your field is not required. Did you post an empty form? Is your field read-only or did you typed something in the form field manually? More info could be useful in resolving this issue.

@simon-the-shark
Copy link
Owner

Just share any information that you think may be useful in reproducing this bug and then resolving this issue.

@simon-the-shark simon-the-shark added the more-information-needed Further information is needed for resolving this issue label Jul 8, 2020
@ejk3052
Copy link
Author

ejk3052 commented Jul 8, 2020 via email

@no-response no-response bot removed the more-information-needed Further information is needed for resolving this issue label Jul 8, 2020
@simon-the-shark
Copy link
Owner

Okay. I'm closing this issue, but you can reopen it if you encounter the same bug or open a new one whenever my package causes any troubles. Good luck with your project!

@suyashgithub
Copy link

Hello,

I get index error - string index out of range, when I save the form
Screenshot 2020-06-09 at 7 50 15 PM
Screenshot 2020-06-09 at 7 48 52 PM

i tried this code in model.py just put try block to handle type error and it fixed locally.
def get_prep_value(self, value):
if value is None:
return value

    if isinstance(value, str):
        return self.save_string(value)
    try:
        return "{},{}".format(value[0], value[1])
    except TypeError:
        print('TypeError')

@simon-the-shark
Copy link
Owner

@suyashgithub Of course, the try-except block eliminates error raising, but it probably doesn't eliminate the cause of this problem. It's a remedy only for symptoms of an issue. The get_prep_value() function is a crucial part of Django's field behavior (it converts the python value to the one that saved to the database) and the errors there shouldn't be ignored.

I worked on a similar case in the #15 issue, but that was about the direct saving of strings to the database. According to your screenshot, your value is an empty string(''), so I guess it should satisfy the isinstance(value, str) if-check and then after self.save_string() affection saved to db without even entering the 45th line.

That's why I'm surprised that you still encounter this issue. I can take a closer look, but I need some details e.g. what's your configuration and what are you doing. I tried posting an empty form to a nullable field on my local machine and everything worked as expected.

@simon-the-shark simon-the-shark added the more-information-needed Further information is needed for resolving this issue label Jul 16, 2020
@suyashgithub
Copy link

I am using
Python 3.6.2
Django==3.0.8
psql (11.3, server 10.8)

in my model i am using like this way

from mapbox_location_field.models import LocationField
class Customer(models.Model):
location = LocationField(map_attrs={"track_location_button": True} )

@simon-the-shark simon-the-shark removed the more-information-needed Further information is needed for resolving this issue label Jul 16, 2020
@simon-the-shark
Copy link
Owner

When exactly do you see this error? Are you doing something unexpected or just post a form? I'm asking because everything is wired. Your field is not nullable, but the value you have is an empty string? Apart from that, an empty string shouldn't cause an error like this in the latest version of my package.

I recommend you to try to run my live demo on your machine to see if this error still raise.

@simon-the-shark simon-the-shark added the more-information-needed Further information is needed for resolving this issue label Jul 17, 2020
@no-response
Copy link

no-response bot commented Jul 31, 2020

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is needed for resolving this issue
Projects
None yet
Development

No branches or pull requests

3 participants