question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Locale not respected for business.currency_iso_code()

See original GitHub issue

Bug report

What’s wrong

I’m trying to use mimesis to generate mock data for tests I’m going to develop and am writing schema to do so.

I set the locale when instantiating an object of class Field(), but on calling business.currency_iso_code() I get random ISO currency codes, whilst I was expecting (or hoping!) to get those for the current locale.

import random
from mimesis.schema import Field, Schema

class SlotData2():
    def __init__(self, locale, max_currency=10):
        self.field = Field(locale)
        self.max_currency = max_currency

    def _generate_cost(self):
        cost = (
            lambda: {
                'amount': self.field('business.price'),
                'currency': self.field('business.currency_iso_code'),
            }
        )
        cost_schema = Schema(schema=cost)
        return cost_schema.create(random.randint(1, self.max_currency))

The business.price is always the correct locale, but the business.currency_iso_code varies as the following shows…

In [200]: test2 = SlotData2('en-gb', 10)

In [201]: test2._generate_cost()
Out[201]: 
[{'amount': '196.66 £', 'currency': 'BZD'},
 {'amount': '223.12 £', 'currency': 'VUV'}]

In [202]: test2._generate_cost()
Out[202]: 
[{'amount': '626.08 £', 'currency': 'XCD'},
 {'amount': '904.78 £', 'currency': 'BOV'},
 {'amount': '836.96 £', 'currency': 'XUA'},
 {'amount': '529.19 £', 'currency': 'LYD'},
 {'amount': '341.14 £', 'currency': 'ILS'},
 {'amount': '136.68 £', 'currency': 'MGA'},
 {'amount': '691.84 £', 'currency': 'KHR'},
 {'amount': '493.02 £', 'currency': 'SDG'},
 {'amount': '250.04 £', 'currency': 'BGN'},
 {'amount': '649.36 £', 'currency': 'AUD'}]

In [203]: test2._generate_cost()
Out[203]: 
[{'amount': '963.86 £', 'currency': 'MNT'},
 {'amount': '707.13 £', 'currency': 'TRY'},
 {'amount': '322.74 £', 'currency': 'SHP'}]

I checked with Generic('en-gb') and it too returns random ISO currency codes rather than the expected GBP

In [204]: g = Generic('en-gb')

In [205]: g.business.currency_iso_code()
Out[205]: 'AFN'

In [206]: g.business.currency_iso_code()
Out[206]: 'USD'

In [207]: g.business.currency_iso_code()
Out[207]: 'ALL'

How is that should be

I would expect business.currency_iso_code() to return the code for the specified locale.

System information

python --version
Python 3.6.7
In [209]: mimesis.__version__
Out[209]: '3.1.0'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
sinecodecommented, Apr 1, 2019

@lk-geimfari @slackline I’m working on this

1reaction
slacklinecommented, Apr 1, 2019

Thanks for the rapid response @lk-geimfari. I’ve started looking at the code to see if I could come up with a solution, if I can work it out before then I’ll submit a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

respect locale preferences but move the currency code always ...
If you want .currencyISOCode but currency always on the right, the simplest solution is not to let the formatter handle currency at all....
Read more >
How to access the Organization "Currency Locale" ISO Locale ...
UserInfo.getDefaultCurrency() returns, helpfully, the ISO Currency Code part of the Currency Locale field. However, there is no way to get at ...
Read more >
Language, Locale, and Currency Settings - Salesforce Help
The Salesforce settings for language, locale, time zone, and currency can affect how objects, such as Accounts, ... Default Currency ISO Code, Not...
Read more >
SOQL and SOSL Reference - Salesforce Implementation guides
You can't use the toLabel()method in a WHERE clause for division or currency ISO code picklists. Filtering on Boolean Fields.
Read more >
NumberFormatTest.java - Android Code Search
public void TestParseNegativeWithAlternativeMinusSign() { ... currency ISO code to be formatted, ... Test that other whitespace characters do not work.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found