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

pyodide crash on a formula that works with gvisor #1331

Open
1 of 2 tasks
mmaura opened this issue Dec 3, 2024 · 0 comments
Open
1 of 2 tasks

pyodide crash on a formula that works with gvisor #1331

mmaura opened this issue Dec 3, 2024 · 0 comments

Comments

@mmaura
Copy link

mmaura commented Dec 3, 2024

Describe the current behavior

I use a modified version of the substitution by templates (https://support.getgrist.com/examples/2023-07-proposals-contracts/).
I added a function to get the days and months in French in the substitution of template. After adding this function (with the sandbox pyodide) it becomes impossible to add columns to any table, the error message appears :

error [pyodide error] RangeError: Maximum call stack size exceeded at wasm://wasm/02239a6e:wasm-function[3174]:0x25deab at wasm://wasm/02239a6e:wasm-function[3175]:0x26a9f5 at wasm://wasm/02239a6e:wasm-function[1045]:0x1asm9was/029/01a60/0wasm-function[2490]:0x1fdbb7 at wasm://wasm/02239a6e:wasm-function[2114]:0x1e4dbd at wasm://wasm/02239a6e:wasm-function[3174]:0x26719b at wasm://wasm/02239a6e:wasm-function[3175]:0x26a9m/15 wasm5

If I change the sandbox to gvisor, then the document works correctly.

Steps to reproduce

Duplicate

You can duplicate https://igrist.sdis66.fr/o/docs/ukJ1W3WQi7qb/Evenements-Anonymise?utm_id=share-doc

code

from datetime import datetime

# Dictionnaires de traduction
jours_fr = {
    "Monday": "Lundi", "Mon": "Lun",
    "Tuesday": "Mardi", "Tue": "Mar",
    "Wednesday": "Mercredi", "Wed": "Mer",
    "Thursday": "Jeudi", "Thu": "Jeu",
    "Friday": "Vendredi", "Fri": "Ven",
    "Saturday": "Samedi", "Sat": "Sam",
    "Sunday": "Dimanche", "Sun": "Dim",
}
mois_fr = {
    "January": "Janvier", "Jan": "Jan",
    "February": "Février", "Feb": "Fév",
    "March": "Mars", "Mar": "Mar",
    "April": "Avril", "Apr": "Avr",
    "May": "Mai", "May": "Mai",
    "June": "Juin", "Jun": "Jun",
    "July": "Juillet", "Jul": "Jul",
    "August": "Août", "Aug": "Aoû",
    "September": "Septembre", "Sep": "Sep",
    "October": "Octobre", "Oct": "Oct",
    "November": "Novembre", "Nov": "Nov",
    "December": "Décembre", "Dec": "Déc",
}


# Finds all data associated with this record
class Find_Data(dict):
    def __missing__(self, key):
        # Si la clé existe comme attribut dans `rec`
        if hasattr(rec, key):
            return getattr(rec, key)
        
        # Vérifie si la clé est un appel de fonction (exemple : "format_date(birth_date, '%d/%m/%Y')")
        match = re.match(r"(\w+)\((.+)\)", key)
        if match:
            func_name, args = match.groups()
            args = [arg.strip(" '\"") for arg in args.split(",")]  # Traite les arguments comme des chaînes
            if func_name in self:
                return self[func_name](*args)  # Appelle la fonction correspondante
            
        raise KeyError(f"La clé ou l'attribut '{key}' est introuvable.")

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self["format_date"] = self.format_date  # Ajoute la fonction comme une clé

    #@staticmethod
    def format_date(date, fmt="%d %B %Y"):
        """Formate une date en français."""
        formatted_date = getattr(rec, date).strftime(fmt)
            # Traduction des jours
        for eng, fr in jours_fr.items():
            formatted_date = formatted_date.replace(eng, fr)
    
        # Traduction des mois
        for eng, fr in mois_fr.items():
            formatted_date = formatted_date.replace(eng, fr)
        
        return formatted_date


# Finds the "modele" template in the Templates table
template = Templates.lookupOne(nom="ev_rapport1").modele

# Formats the template with fields from this table as well as fields from the referenced table
template.format_map(Find_Data())

Template:

<p><span style="color: #ff9900; font-size: 1em;">{Etablissement.Nom_complet}</span><br />
<span style="color: #ff9900;">{Type}</span><br />
<span style="font-size: 0.7em;">Du {format_date(Date_debut, '%A %d %B %Y %Ih%M')} au {format_date(Date_fin, '%A %d %B %Y %Ih%M')}.<br />Il y a {Nb_Attendus} places, limite des inscriptions le {format_date(Date_limite, '%A %d %B %Y')}. <br />
</span> <span style="color: #ff9900; font-size: 1.2em;">Lieu </span><br />
<span style="font-size: 0.7em;">{Etablissement.Contact}<br />
{Etablissement.Adresse_complete_html}<br />
waze://?ll={Etablissement.Latitude},{Etablissement.Longitude}&amp;z=10</span><br />
 <span style="color: #ff9900; font-size: 1.2em;">Complément d'information </span><br/>
<span>{Complement_d_information}</span></p>

Describe the expected behavior

No response

Where have you encountered this bug?

Instance information (when self-hosting only)

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

No branches or pull requests

1 participant