Closed hramezani closed 2 years ago
There is an issue in my case. I have a pickled jdatetime object with the older version, and now there is a problem when I try to retrieve it with the new version of jdatetime. I had to fix all the instances of the jdatetime manually which was a little cumbersome. It took a lot of time for me to spot the issue because both versions work fine alone!
This experiment using bash version 4.4.20 and python version 3.9.7 indicates the exact issue (upgarding from jdatetime 3.7.0 to 3.8.1):
bash :
# installing an old version of jdatetime
pip uninstall jdatetime
pip install -Iv jdatetime==3.7.0
pthon:
import jdatetime
import pickle
# saving a jdatetime object using pickle file foo.pickle
with open('foo.pickle', 'wb') as ofile:
pickle.dump(jdatetime.datetime.now(), ofile)
now = jdatetime.datetime.now()
print(f'{now:%Y/%m/%d %H:%M}')
# OK! Fine! prints formatted date/time
bash:
# upgrading to new version : (3.8.1)
pip install --upgrade jdatetime
pthon:
import jdatetime
import pickle
# retrieving the previous jdatetime object:
with open('foo.pickle', 'rb') as ifile:
then = pickle.load(ifile)
# now try to print formatted object:
print(f'{then:%Y/%m/%d %H:%M}')
# trouble!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/XXXX/.virtualenvs/minon/lib/python3.9/site-packages/jdatetime/__init__.py", line 579, in __format__
return self.strftime(format)
File "/home/XXXX/.virtualenvs/minon/lib/python3.9/site-packages/jdatetime/__init__.py", line 640, in strftime
if symbol in self._strftime_mapping:
AttributeError: 'datetime' object has no attribute '_strftime_mapping'
Fixes https://github.com/slashmili/python-jalali/issues/108